#include <bits/stdc++.h>
using namespace std;
int dirx[4] = {0, 0, -1, 1};
int diry[4] = {1, -1, 0, 0};
char s[55][55];
int vis[55][55];
int n, m, ans;
void dfs(int x, int y) {
  ans++;
  int xx, yy, i;
  for (i = 0; i < 4; i++) {
    xx = dirx[i] + x;
    yy = diry[i] + y;
    if (xx >= 0 && yy >= 0 && xx < n && yy < m && !vis[xx][yy] &&
        s[xx][yy] == '#') {
      vis[xx][yy] = 1;
      dfs(xx, yy);
    }
  }
}
int main() {
  int i, j, num = 0;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%s", s[i]);
    for (j = 0; j < m; j++) {
      if (s[i][j] == '#') {
        num++;
      }
    }
  }
  if (num < 3) {
    printf("-1\n");
    return 0;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == '#') {
        memset(vis, 0, sizeof(vis));
        vis[i][j] = 1;
        ans = 0;
        for (int p = 0; p < n; p++) {
          for (int q = 0; q < m; q++) {
            if (s[p][q] == '#' && !vis[p][q]) {
              vis[p][q] = 1;
              dfs(p, q);
              goto loop;
            }
          }
        }
      loop:;
        if (ans != num - 1) {
          printf("1\n");
          return 0;
        }
      }
    }
  }
  printf("2\n");
  return 0;
}
