#include <bits/stdc++.h>
char f[55][55];
short v[55][55];
int check(int i, int j, int n, int m) {
  if (i >= 0 && i < n && j >= 0 && j < m) {
    return 1;
  }
  return 0;
}
void recur(int i, int j, int n, int m) {
  v[i][j] = 1;
  if (check(i + 1, j, n, m) && f[i + 1][j] == '#' && v[i + 1][j] == 0) {
    recur(i + 1, j, n, m);
  }
  if (check(i, j + 1, n, m) && f[i][j + 1] == '#' && v[i][j + 1] == 0) {
    recur(i, j + 1, n, m);
  }
  if (check(i - 1, j, n, m) && f[i - 1][j] == '#' && v[i - 1][j] == 0) {
    recur(i - 1, j, n, m);
  }
  if (check(i, j - 1, n, m) && f[i][j - 1] == '#' && v[i][j - 1] == 0) {
    recur(i, j - 1, n, m);
  }
}
void solve(int n, int m) {
  int i, j, k, t, flag, count;
  count = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (f[i][j] == '#') {
        count++;
      }
    }
  }
  if (count <= 2) {
    printf("-1\n");
    return;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (f[i][j] == '#') {
        f[i][j] = '.';
        memset(v, 0, sizeof(v));
        flag = 0;
        for (k = 0; k < n; k++) {
          for (t = 0; t < m; t++) {
            if (f[k][t] == '#' && v[k][t] == 0) {
              if (flag == 1) {
                printf("1\n");
                return;
              }
              flag = 1;
              recur(k, t, n, m);
            }
          }
        }
        f[i][j] = '#';
      }
    }
  }
  printf("2\n");
}
int main() {
  int n, m, i;
  while (scanf("%d%d", &n, &m) == 2) {
    for (i = 0; i < n; i++) {
      scanf("%s", f[i]);
    }
    solve(n, m);
  }
  return 0;
}
