input: from typing import List
  
  def solve_maze(n: int, m: int, grid: List[List[int]]) -> List[int]:
      """ Solve a maze represented by a 2D grid of size n x m where 1 represents a walkable path and 0 represents a wall.
      The maze starts at the top-left corner (0, 0) and ends at the bottom-right corner (n-1, m-1).
      The function returns a list of values indicating the path taken from start to end.
      >>> solve_maze(3, 3, [[1, 0, 0], [1, 1, 0], [0, 1, 1]])
      [1, 2, 3]
      >>> solve_maze(2, 2, [[1, 1], [0, 1]])
      [1, 2]
      """
output:     directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
      path = []
      visited = [[False] * m for _ in range(n)]
  
      def dfs(x, y, step):
          if x == n - 1 and y == m - 1:
              path.append(step)
              return True
          visited[x][y] = True
          path.append(step)
          for dx, dy in directions:
              nx, ny = x + dx, y + dy
              if 0 <= nx < n and 0 <= ny < m and not visited[nx][ny] and grid[nx][ny] == 1:
                  if dfs(nx, ny, step + 1):
                      return True
          path.pop()
          return False
  
      dfs(0, 0, 1)
      return path