#include <bits/stdc++.h>
using namespace std;
const int N = 52, inf = 1e9, mod = 1e9 + 7;
const long long linf = 1e18;
int K, n, m, k, dir[4][2];
bool used[N][N];
char c[N][N];
bool check(int x, int y) {
  return x >= 1 && y >= 1 && x <= n && y <= m && c[x][y] == '#';
}
void dfs(int x, int y) {
  used[x][y] = 1;
  K++;
  for (int i = 0; i < 4; i++) {
    int xa = x + dir[i][0];
    int ya = y + dir[i][1];
    if (check(xa, ya) && !used[xa][ya]) dfs(xa, ya);
  }
}
int main() {
  dir[0][0] = dir[1][1] = 1;
  dir[2][0] = dir[3][1] = -1;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
      if (c[i][j] == '#') k++;
    }
  if (k <= 2) {
    printf("-1");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (c[i][j] == '#') {
        c[i][j] = '.';
        memset(used, 0, sizeof used);
        K = 0;
        for (int q = 0; q < 4; q++) {
          int x = i + dir[q][0];
          int y = j + dir[q][1];
          if (check(x, y) && !used[x][y]) {
            dfs(x, y);
            if (K != k - 1) {
              printf("1");
              return 0;
            } else
              break;
          }
        }
        c[i][j] = '#';
      }
    }
  printf("2");
  return 0;
}
