#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int inf = (int)1e9;
const int MAX_N = 100 * 1000 + 1000;
int n, m, total;
char arr[111][111];
bool mark[111][111];
vector<int> qi, qj;
int ai[] = {1, -1, 0, 0};
int bj[] = {0, 0, 1, -1};
int aii[] = {1, -1, 1, -1};
int bjj[] = {1, -1, -1, 1};
int ok(int x) {
  memset(mark, 0, sizeof mark);
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (arr[i][j] == '#') break;
    }
    if (j < m) break;
  }
  if (j == m) return 0;
  int ret = 1;
  qi.clear();
  qj.clear();
  qi.push_back(i);
  qj.push_back(j);
  mark[i][j] = 1;
  for (int head = 0; head < ((int)qi.size()); head++) {
    int ii = qi[head];
    int jj = qj[head];
    for (int k = 0; k < 4; k++) {
      int ni = ii + ai[k];
      int nj = jj + bj[k];
      if (!(ni >= 0 && nj >= 0 && ni < n && nj < m && arr[ni][nj] == '#' &&
            mark[ni][nj] == 0))
        continue;
      qi.push_back(ni);
      qj.push_back(nj);
      mark[ni][nj] = 1;
      ret++;
    }
  }
  return ret < total - x;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
      total += (arr[i][j] == '#');
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == '.') continue;
      arr[i][j] = '.';
      if (ok(1)) {
        cout << 1 << endl;
        return 0;
      }
      arr[i][j] = '#';
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == '.') continue;
      for (int k = 0; k < 4; k++) {
        int ii = i + aii[k];
        int jj = j + bjj[k];
        if (!(ii >= 0 && jj >= 0 && ii < n && jj < m)) continue;
        if (arr[ii][jj] == '.') continue;
        arr[i][j] = arr[ii][jj] = '.';
        if (ok(2)) {
          cout << 2 << endl;
          return 0;
        }
        arr[i][j] = arr[ii][jj] = '#';
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
