CodeLab Academy 📞 9936 6696
← List Python · Level 10: Algorithms Code · 100 points ← #922 #924 →

#923. Maze (BFS)

You get a grid with `.` and `#` cells. Find the smallest number of steps from the top-left to the bottom-right, moving in 4 directions. If it is impossible, print -1. ### Input n m, then n lines. ### Output A number.

Examples

Input
5 6
.##..#
#.....
#...#.
.##.##
#..#..
Output
-1
Input
5 5
.....
##.#.
....#
.#...
.#...
Output
8

💡 You can solve it with Python, JavaScript or blocks. Read the input line by line with input(). Don't print a question (like input("Number: ")). Print exactly what the output asks for, nothing more.

🔒 You can solve the first 3 problems without an account. Sign up for free to solve this one!