#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const double PI = 3.141592653589793238462643383279;
int n, m, ans = 2, coun;
char a[100][100];
bool was[100][100];
int b[5] = {0, -1, 1, 0, 0};
int c[5] = {0, 0, 0, -1, 1};
void dfs(int vx, int vy) {
  was[vx][vy] = 1;
  for (int i = 1; i <= 4; i++) {
    int tox = vx + b[i], toy = vy + c[i];
    if (tox >= 1 && tox <= n && toy >= 1 && toy <= m && !was[tox][toy]) {
      dfs(tox, toy);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.') {
        was[i][j] = 1;
      } else {
        coun++;
      }
    }
  }
  if (coun <= 2) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      was[i][j] = 1;
      int cur = 0;
      for (int ii = 1; ii <= n; ii++) {
        for (int jj = 1; jj <= m; jj++) {
          if (!was[ii][jj]) {
            cur++;
            dfs(ii, jj);
          }
        }
      }
      for (int ii = 1; ii <= n; ii++) {
        for (int jj = 1; jj <= m; jj++) {
          if (a[ii][jj] == '#') {
            was[ii][jj] = 0;
          }
        }
      }
      if (cur > 1) {
        cout << 1;
        return 0;
      }
    }
  }
  cout << 2;
}
