#include <bits/stdc++.h>
using namespace std;
ifstream fin("alfa.in");
ofstream fout("alfa.out");
bool a[52][52];
int dl[4] = {-1, 0, 1, 0};
int dc[4] = {0, 1, 0, -1};
queue<int> ql, qc;
int bfs(int ls, int cs) {
  int i, la, ca, lv, cv;
  bool b[52][52] = {};
  int nr = 1;
  b[ls][cs] = 1;
  ql.push(ls);
  qc.push(cs);
  while (ql.empty() == 0) {
    la = ql.front();
    ca = qc.front();
    ql.pop();
    qc.pop();
    for (i = 0; i < 4; i++) {
      lv = la + dl[i];
      cv = ca + dc[i];
      if (a[lv][cv] && !b[lv][cv]) {
        b[lv][cv] = 1;
        nr++;
        ql.push(lv);
        qc.push(cv);
      }
    }
  }
  return nr;
}
int main() {
  int n, m, i, j, k, nr2, nr = 0;
  char c;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      cin >> c;
      if (c == '#') {
        a[i][j] = 1;
        nr++;
      } else
        a[i][j] = 0;
    }
  if (nr <= 2) {
    cout << -1;
    return 0;
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (a[i][j]) {
        a[i][j] = 0;
        for (k = 0; k < 4; k++)
          if (a[i + dl[k]][j + dc[k]]) {
            nr2 = bfs(i + dl[k], j + dc[k]);
            break;
          }
        a[i][j] = 1;
        if (nr2 < nr - 1) {
          cout << 1;
          return 0;
        }
      }
  cout << 2;
  return 0;
}
