input: 
  def solve_maze(n: int, m: int, grid: List[List[int]]) -> List[int]:
      """ Solve the given maze represented by a grid of size n x m where 0's represent walls and 1's represent paths.
      The maze is assumed to have a single path from the top-left corner (0, 0) to the bottom-right corner (n-1, m-1).
      The function should return the list of cell values on the path from start to end.
      >>> solve_maze(3, 3, [[1, 0, 0], [1, 1, 0], [0, 1, 1]])
      [0, 3, 5]
      >>> solve_maze(2, 2, [[1, 1], [1, 1]])
      [0, 1]
      """
  
output:     def is_valid(x, y):
          return 0 <= x < n and 0 <= y < m and grid[x][y] == 1
  
      def dfs(x, y, path):
          if x == n - 1 and y == m - 1:
              return True
          for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
              nx, ny = x + dx, y + dy
              if is_valid(nx, ny) and (nx, ny) not in visited:
                  visited.add((nx, ny))
                  path.append(nx * m + ny)
                  if dfs(nx, ny, path):
                      return True
                  path.pop()
          return False
  
      visited = set()
      path = [0]
      visited.add((0, 0))
      dfs(0, 0, path)
      return path