Gomgomi's Diet Management 2
Time limit3.5sMemory limit1024 MB
Given a grid with obstacles, find the fewest new obstacles that cut every path from the top-left cell to the bottom-right cell.
Problem

The grid has rows and columns, and a delicious chicken is placed at cell . Gomgomi starts at and wants to reach the chicken. Gomgomi can move up, down, left, and right freely, but cannot step onto a cell with an obstacle or leave the grid.

Chungchung, Gomgomi's health trainer, decides to stop Gomgomi from reaching the chicken. Chungchung can place a new obstacle on any cell that currently has no obstacle to block the path. If some cells already have obstacles, Chungchung may be able to place fewer new ones.
Given the state of the grid, print the minimum number of additional obstacles Chungchung must place to block Gomgomi from reaching the chicken. Obstacles cannot be placed on or .
Input
The first line contains integers and separated by a space. (, )
From the second line onward, the next lines give the state of the grid. means a cell that can be passed through, and means a cell with an obstacle that cannot be passed through.
It is guaranteed that and have no obstacles.
Output
Print the minimum number of additional obstacles Chungchung must place to block Gomgomi's movement.