#include <bits/stdc++.h>
using namespace std;
char g[55][55];
int viz[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int v[55][55], low[55][55], pre[55][55], dfsn;
int paia[55][55], paib[55][55];
int a, b;
int tem;
int n, m;
void dfs(int i, int j) {
  v[i][j] = 1;
  low[i][j] = pre[i][j] = dfsn++;
  int raiz = (-1 == paia[i][j]) && (-1 == paib[i][j]);
  int deg = 0;
  for (int a = 0; a < 4; a++) {
    int ni = i + viz[a][0], nj = j + viz[a][1];
    if (ni >= 0 && ni < n && nj >= 0 && nj < m) {
      if (g[ni][nj] == '#' && !(paia[i][j] == ni && paib[i][j] == nj)) {
        if (!v[ni][nj]) {
          paia[ni][nj] = i;
          paib[ni][nj] = j;
          dfs(ni, nj);
          if (!raiz && low[ni][nj] >= pre[i][j]) {
            tem = 1;
          }
          deg++;
          low[i][j] = min(low[i][j], low[ni][nj]);
        } else {
          low[i][j] = min(low[i][j], pre[ni][nj]);
        }
      }
    }
  }
  if (raiz && deg >= 2) {
    tem = 1;
  }
}
int main() {
  int q = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf(" %c", &g[i][j]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '#') {
        q++;
        a = i;
        b = j;
      }
    }
  if (q <= 2)
    printf("-1\n");
  else {
    tem = 0;
    dfsn = 0;
    memset(v, 0, sizeof v);
    paia[a][b] = -1;
    paib[a][b] = -1;
    dfs(a, b);
    if (tem)
      printf("1\n");
    else
      printf("2\n");
  }
  return 0;
}
