Given a 2D grid represented as a list of lists, where 0 represents an open cell and 1 represents a wall, implement a BFS algorithm to find the shortest path from the top-left corner (0, 0) to the bottom-right corner (n-1, m-1). If no path exists, return -1.
Example 1:
Input: grid = [[0,0,0],[0,1,0],[0,0,0]]
Output: 4
Explanation: The shortest path is 4 steps: (0,0) -> (0,1) -> (0,2) -> (1,2) -> (2,2).
Example 2:
Input: grid = [[0,0,0],[0,1,0],[1,1,0]]
Output: 5
Explanation: The shortest path is 5 steps: (0,0) -> (0,1) -> (0,2) -> (1,2) -> (2,2).
1 <= grid.length, grid[i].length <= 1000s and 1s.