Field of dreams
Write a program to find the minimum number of g cells that must be replaced by d cells such that grid is disconnected. If the grid is initially disconnected print 0.
Input format
Output format
Print the minimum number of g cells that must be replaced by d cells such that the grid is disconnected. If the grid is initially disconnected, print 0.
Contraints
1<= N
M <= 400
Sample Input
ggg
gdg
ggg
Sample Output
2
Explanation
You can convert 2 g to d to convert the grid into following:
ggd
gdg
dgg
The grid is no longer connected.