#include <bits/stdc++.h>
using namespace std;
int X[] = {1, 0, -1, 0};
int Y[] = {0, 1, 0, -1};
string T[100];
int n, m;
bool cmp[100][100];
void dfs(int x, int y) {
  cmp[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int xx = x + X[i], yy = y + Y[i];
    if (xx >= 0 && xx < n && yy >= 0 && yy < m && !cmp[xx][yy] &&
        T[xx][yy] == '#') {
      dfs(xx, yy);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> T[i];
  int num = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++)
      if (T[i][j] == '#') {
        num++;
        T[i][j] = '.';
        memset(cmp, 0, sizeof cmp);
        int cont = 0;
        for (int aa = 0; aa < n; aa++) {
          for (int bb = 0; bb < m; bb++)
            if (T[aa][bb] == '#') {
              if (!cmp[aa][bb]) {
                cont++;
                dfs(aa, bb);
              }
            }
        }
        if (cont > 1) {
          cout << 1 << endl;
          return 0;
        }
        T[i][j] = '#';
      }
  }
  if (num <= 2)
    cout << -1 << endl;
  else
    cout << 2 << endl;
  return 0;
}
