#include using namespace std; int w, h; vector> c; void replace(int i, int j, int n) { if (c[i][j] == 1) { c[i][j] = n; replace(i + 1, j, n); replace(i - 1, j, n); replace(i, j + 1, n); replace(i, j - 1, n); } return; } int main() { cin >> w >> h; c.resize(h); for (int i = 0;i < h;i++) { string s; cin >> s; c[i].resize(w); for (int j = 0;j < w;j++) { if (s[j] == '#') { c[i][j] = 0; } else { c[i][j] = 1; } } } int count = 0; for (int i = 1;i < h-1;i++) { for (int j = 1;j < w-1;j++) { if (c[i][j] == 1) { replace(i, j, count + 2); count++; } if (count==2) break; } if (count == 2) break; } int mi = 20 * 20; for(int i=1;i