#include <bits/stdc++.h>
const int N = 50 + 10;
char a[N][N];
int n, m;
void read() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", a[i]);
  }
}
bool been[N][N];
int px[] = {1, -1, 0, 0};
int py[] = {0, 0, 1, -1};
bool ok(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
int dfs(int x, int y) {
  been[x][y] = true;
  int cnt = 1;
  for (int k = 0; k < 4; ++k) {
    int x1 = x + px[k], y1 = y + py[k];
    if (ok(x1, y1) && a[x1][y1] == '#' && !been[x1][y1]) {
      cnt += dfs(x1, y1);
    }
  }
  return cnt;
}
bool connected() {
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '#') {
        ++cnt;
      }
      been[i][j] = false;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '#') {
        if (dfs(i, j) != cnt) {
          return false;
        } else {
          return true;
        }
      }
    }
  }
  return true;
}
int main() {
  read();
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '#') {
        ++cnt;
      }
    }
  }
  if (cnt < 3) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '#') {
        a[i][j] = '.';
        if (!connected()) {
          printf("1\n");
          return 0;
        }
        a[i][j] = '#';
      }
    }
  }
  printf("2\n");
  return 0;
}
