input: from typing import List
  
  
  def maze_solver(maze_grid: List[List[int]]) -> List[int]:
      """ Solve the maze by finding the shortest path from the start (0, 0) to the end (n-1, m-1).
      The maze is represented as a 2D list where 1's represent valid paths and 0's represent walls.
      The function should return a list of integers representing the shortest path length.
      >>> maze_solver([[1, 0, 1], [1, 1, 0], [1, 1, 1]])
      [4]
      >>> maze_solver([[1, 0, 0], [1, 1, 1], [1, 0, 1]])
      [6]
      """
output:     
      n = len(maze_grid)
      m = len(maze_grid[0])
      directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
      queue = [(0, 0, 0)]
      visited = set((0, 0))
  
      while queue:
          x, y, dist = queue.pop(0)
          if x == n - 1 and y == m - 1:
              return [dist + 1]
          for dx, dy in directions:
              nx, ny = x + dx, y + dy
              if 0 <= nx < n and 0 <= ny < m and maze_grid[nx][ny] == 1 and (nx, ny) not in visited:
                  visited.add((nx, ny))
                  queue.append((nx, ny, dist + 1))
  
      return []
  