input: from typing import List
  
  
  def solve_maze(n: int, m: int, grid: List[List[int]]) -> List[int]:
      """ Solve a maze represented as a 2D grid. The maze has dimensions n x m, with the start at the top-left corner (0, 0) and the end at the bottom-right corner (n-1, m-1). Each cell in the grid is either 1 (passable) or 0 (blocked). The function should return a list of cell values corresponding to the path taken to solve the maze, where each subsequent value represents a step towards the end.
      >>> solve_maze(3, 3, [[1, 0, 0], [1, 1, 0], [0, 1, 1]])
      [2, 3, 4]
      >>> solve_maze(4, 4, [[1, 1, 1, 0], [0, 1, 0, 0], [0, 1, 1, 1], [0, 0, 1, 1]])
      [3, 4, 5, 6]
      """
output:     
      if grid[0][0] == 0 or grid[n-1][m-1] == 0:
          return []
      
      directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
      queue = [(0, 0, 1)]
      visited = set((0, 0))
      path = []
      
      while queue:
          x, y, step = queue.pop(0)
          path.append(step)
          
          if x == n - 1 and y == m - 1:
              return path
          
          for dx, dy in directions:
              nx, ny = x + dx, y + dy
              if 0 <= nx < n and 0 <= ny < m and (nx, ny) not in visited and grid[nx][ny] == 1:
                  visited.add((nx, ny))
                  queue.append((nx, ny, step + 1))
      
      return []
  