#include <bits/stdc++.h>
using namespace std;
const int maxN = 55;
const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
int n, m, nsquare;
char a[maxN][maxN];
pair<int, int> qu[maxN * maxN];
int top, bot, d[maxN][maxN];
void enter() {
  scanf("%d%d", &n, &m);
  nsquare = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s", a[i]);
    for (int j = m; j >= 1; j--) {
      a[i][j] = a[i][j - 1];
      if (a[i][j] == '#') nsquare++;
    }
  }
}
bool bfs() {
  bot = 1;
  top = 0;
  memset(d, true, sizeof d);
  for (int i = 1; i <= n && top == 0; i++)
    for (int j = 1; j <= m && top == 0; j++)
      if (a[i][j] == '#') {
        qu[++top] = make_pair(i, j);
        d[i][j] = false;
        break;
      }
  int x, y, xx, yy;
  while (bot <= top) {
    x = qu[bot].first, y = qu[bot].second;
    bot++;
    for (int i = 0; i < 4; i++) {
      xx = x + dx[i];
      yy = y + dy[i];
      if (xx < 1 || xx > n || yy < 1 || yy > m || a[xx][yy] == '.') continue;
      if (d[xx][yy]) {
        d[xx][yy] = false;
        qu[++top] = make_pair(xx, yy);
      }
    }
  }
  return (top == nsquare - 1);
}
void solve() {
  if (nsquare <= 2) {
    printf("-1\n");
    return;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == '#') {
        a[i][j] = '.';
        if (!bfs()) {
          printf("1\n");
          return;
        }
        a[i][j] = '#';
      }
  printf("2\n");
}
int main() {
  enter();
  solve();
  return 0;
}
