#include <bits/stdc++.h>
using namespace std;
const long maxn = 55;
const long dx[4] = {-1, 0, 0, 1};
const long dy[4] = {0, 1, -1, 0};
bool was[maxn][maxn];
long a[maxn][maxn];
long n, m;
void dfs(long x, long y) {
  was[x][y] = true;
  for (long j = 0; j <= 3; j++) {
    long x1 = x + dx[j];
    long y1 = y + dy[j];
    if ((x1 >= 1) && (x1 <= n) && (y1 >= 1) && (y1 <= m) && (a[x1][y1] == 1) &&
        (!was[x1][y1]))
      dfs(x1, y1);
  }
}
int main() {
  scanf("%ld%ld\n", &n, &m);
  long cht = 0;
  long x, y, q, k;
  for (q = 1; q <= n; q++) {
    for (k = 1; k <= m; k++) {
      char c1;
      scanf("%c", &c1);
      if (c1 == '#') {
        a[q][k] = 1;
        cht++;
      } else
        a[q][k] = 0;
    }
    scanf("\n");
  }
  if (cht <= 2) {
    printf("-1");
    exit(0);
  }
  for (x = 1; x <= n; x++)
    for (y = 1; y <= m; y++)
      if (a[x][y] == 1) {
        a[x][y] = 0;
        bool found = false;
        memset(was, 0, sizeof(was));
        for (q = 1; q <= n; q++) {
          for (k = 1; k <= m; k++)
            if (a[q][k] == 1) {
              found = true;
              dfs(q, k);
              break;
            }
          if (found) break;
        }
        for (q = 1; q <= n; q++)
          for (k = 1; k <= m; k++)
            if ((!was[q][k]) && (a[q][k] == 1)) {
              printf("1");
              exit(0);
            }
        a[x][y] = 1;
      }
  printf("2");
}
