#include <bits/stdc++.h>
using namespace std;
bool a[55][55], b[55][55], c[55][55];
int n, m;
int ans, tot;
int p[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
void judge(int x, int y) {
  c[x][y] = true;
  tot++;
  for (int i = 0; i < 4; i++) {
    int px = p[i][0] + x;
    int py = p[i][1] + y;
    if (px >= 1 && px <= n && py >= 1 && py <= m) {
      if (b[px][py] && !c[px][py]) {
        judge(px, py);
      }
    }
  }
}
void solve() {
  cin >> n >> m;
  char ch;
  ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf(" %c", &ch);
      if (ch == '#')
        ans++, b[i][j] = a[i][j] = true;
      else
        b[i][j] = a[i][j] = false;
    }
  }
  if (ans <= 2) puts("-1"), exit(0);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j]) {
        b[i][j] = false;
        memset(c, false, sizeof(c));
        c[i][j] = true;
        for (int k = 0; k < 4; k++) {
          int px = p[k][0] + i;
          int py = p[k][1] + j;
          if (px >= 1 && px <= n && py >= 1 && py <= m) {
            if (b[px][py] && !c[px][py]) {
              tot = 0;
              judge(px, py);
              break;
            }
          }
        }
        if (tot != ans - 1) puts("1"), exit(0);
        b[i][j] = true;
      }
    }
  }
  puts("2"), exit(0);
}
int main() {
  solve();
  return 0;
}
