Steward the assayer watches over the coral atoll of Pearldeep's stores of halls. A careful computation stands between order and chaos. Task: '.' is open and '#' is blocked. Print the fewest moves (4-directional) from the top-left to bottom-right cell, or -1 if unreachable. Input format: First line: r and c. Next r lines: rows of '.' and '#'. Output format: Print the shortest distance or -1. Constraints: 1 <= r,c <= 160; r*c <= 10^6; endpoints are '.'.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= r,c <= 160; r*c <= 10^6; endpoints are '.'.
