input: from typing import List
  
  def solve_maze(n: int, m: int, grid: List[List[int]]) -> List[int]:
      """ Solves a maze by finding the shortest path from the start (0, 0) to 
      the end (n-1, m-1). The maze is represented by a grid of integers where 
      1 represents a path and 0 represents a wall. The function returns the 
      path length as a list of integers.
      >>> solve_maze(3, 3, [[1, 0, 1], [1, 1, 1], [0, 1, 1]])
      [2]
      >>> solve_maze(4, 4, [[1, 1, 1, 1], [1, 0, 1, 1], [1, 1, 1, 0], [0, 1, 1, 1]])
      [3]
      """
output:     from collections import deque
  
      directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
      queue = deque([(0, 0, 0)])
      visited = set((0, 0))
  
      while queue:
          x, y, dist = queue.popleft()
  
          if (x, y) == (n - 1, m - 1):
              return [dist]
  
          for dx, dy in directions:
              nx, ny = x + dx, y + dy
              if 0 <= nx < n and 0 <= ny < m and grid[nx][ny] == 1 and (nx, ny) not in visited:
                  visited.add((nx, ny))
                  queue.append((nx, ny, dist + 1))
  
      return []