#include <bits/stdc++.h>
using namespace std;
int n, m;
int s[52][52];
bool vis[52][52];
int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
int ct = 0;
int curct = 0;
bool first = false;
int sx[2], sy[2];
void dfs(int x, int y) {
  ++curct;
  vis[x][y] = true;
  for (int i = 0; i < 4; ++i) {
    int dx = x + dir[i][0], dy = y + dir[i][1];
    if (s[dx][dy] && !vis[dx][dy]) {
      dfs(dx, dy);
    }
  }
}
int main() {
  memset(s, 0, sizeof(s));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    char t[55];
    scanf("%s", t);
    for (int j = 1; j <= m; ++j) {
      if (t[j - 1] == '#') {
        if (first) {
          sx[1] = i;
          sy[1] = j;
        } else {
          first = true;
          sx[0] = i;
          sy[0] = j;
        }
        ++ct;
      }
      s[i][j] = (t[j - 1] == '.' ? 0 : 1);
    }
  }
  if (ct < 3) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (s[i][j]) {
        memset(vis, 0, sizeof(vis));
        vis[i][j] = true;
        curct = 0;
        if (sx[0] == i && sy[0] == j)
          dfs(sx[1], sy[1]);
        else
          dfs(sx[0], sy[0]);
        if (curct < ct - 1) {
          goto haha;
        }
      }
    }
  }
haha:
  if (curct < ct - 1)
    printf("1\n");
  else
    printf("2\n");
  return 0;
}
