input: from typing import List
  
  def solve_maze(grid: List[List[int]], n: int, m: int) -> List[int]:
      """ Solve the maze represented by a grid of size n x m where each cell in the grid
      has a value of 1 or 0. A value of 1 indicates a path and a value of 0 indicates a wall.
      The maze starts from the top-left corner (0, 0) and ends at the bottom-right corner 
      (n-1, m-1). The function returns a list of values representing the path from start to end.
      If no path is found, an empty list is returned.
      >>> solve_maze([[1, 0, 0], [1, 1, 0], [0, 1, 1]], 3, 3)
      [1, 2, 3]
      >>> solve_maze([[1, 0], [1, 1]], 2, 2)
      [1, 2]
      """
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 path
          for dx, dy in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
              nx, ny = x + dx, y + dy
              if is_valid(nx, ny):
                  grid[nx][ny] = -1  # Mark as visited
                  result = dfs(nx, ny, path + [len(path) + 1])
                  if result:
                      return result
          return []
  
      if grid[0][0] == 0 or grid[n-1][m-1] == 0:
          return []
      return dfs(0, 0, [1])