#include <bits/stdc++.h>
using namespace std;
char mat[1000][1000];
int mark[1000][1000];
struct node {
  int x, y;
  node(int xx = 0, int yy = 0) {
    x = xx;
    y = yy;
  }
};
int d[4][2];
queue<node> q;
int main() {
  int n, m;
  d[0][0] = 1;
  d[0][1] = 0;
  d[1][0] = -1;
  d[1][1] = 0;
  d[2][0] = 0;
  d[2][1] = 1;
  d[3][0] = 0;
  d[3][1] = -1;
  scanf("%d%d", &n, &m);
  int k = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (j == 1)
        scanf(" %c", &mat[i][j]);
      else
        scanf("%c", &mat[i][j]);
      if (mat[i][j] == '#') {
        k++;
      }
    }
  }
  int ans = 2;
  if (k <= 2)
    printf("%d\n", -1);
  else {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++)
        if (mat[i][j] == '#') {
          for (int i1 = 1; i1 <= n; i1++)
            for (int j1 = 1; j1 <= m; j1++) mark[i1][j1] = 1;
          mat[i][j] = '.';
          bool u = false;
          int kk = 1;
          for (int i1 = 1; i1 <= n; i1++) {
            for (int j1 = 1; j1 <= m; j1++)
              if (mat[i1][j1] == '#') {
                mark[i1][j1] = 0;
                q.push(node(i1, j1));
                while (!q.empty()) {
                  node x = q.front();
                  q.pop();
                  for (int l = 0; l < 4; l++)
                    if (x.x + d[l][0] > 0 && x.x + d[l][0] <= n &&
                        x.y + d[l][1] > 0 && x.y + d[l][1] <= m)
                      if (mat[x.x + d[l][0]][x.y + d[l][1]] == '#' &&
                          mark[x.x + d[l][0]][x.y + d[l][1]] == 1) {
                        mark[x.x + d[l][0]][x.y + d[l][1]] = 0;
                        q.push(node(x.x + d[l][0], x.y + d[l][1]));
                        kk++;
                      }
                }
                u = true;
                break;
              }
            if (u) break;
          }
          if (kk != k - 1) {
            ans = 1;
            break;
          }
          mat[i][j] = '#';
        }
      if (ans == 1) break;
    }
    printf("%d\n", ans);
  }
  return 0;
}
