#include <bits/stdc++.h>
struct eugin {
  int x, y;
};
char a[55][55];
int n, m, s;
eugin w[4];
eugin b[3000];
bool used[55][55];
inline bool check(int x, int y) {
  if (x < 0) return false;
  if (x >= n) return false;
  if (y < 0) return false;
  if (y >= m) return false;
  if (a[x][y] == '.') return false;
  if (used[x][y]) return false;
  return true;
}
inline bool work() {
  int head, tail, i, j, x, y;
  bool f;
  memset(used, false, sizeof(used));
  f = false;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++)
      if (a[i][j] == '#') {
        b[1].x = i;
        b[1].y = j;
        f = true;
        break;
      }
    if (f) break;
  }
  used[b[0].x][b[0].y] = true;
  head = 0;
  tail = 1;
  j = 1;
  do {
    head++;
    for (i = 0; i < 4; i++) {
      x = b[head].x + w[i].x;
      y = b[head].y + w[i].y;
      if (check(x, y)) {
        tail++;
        b[tail].x = x;
        b[tail].y = y;
        used[x][y] = true;
        j++;
        if (j == s - 1) return true;
      }
    }
  } while (head < tail);
  if (j < s - 1) return false;
  return true;
}
int main() {
  int i, j, x, y;
  s ^= s;
  memset(w, 0, sizeof(w));
  w[0].x = -1;
  w[1].y = 1;
  w[2].x = 1;
  w[3].y = -1;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%s", a[i]);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      if (a[i][j] == '#') s++;
  if (s == 1)
    puts("-1");
  else if (s == 2)
    puts("-1");
  else if (s == 3)
    puts("1");
  else {
    for (i = 0; i < n; i++)
      for (j = 0; j < m; j++)
        if (a[i][j] == '#') {
          a[i][j] = '.';
          if (!work()) {
            puts("1");
            return 0;
          }
          a[i][j] = '#';
        }
    puts("2");
  }
  return 0;
}
