#include <bits/stdc++.h>
using namespace std;
int n, m, num;
int step[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
char s[51][51];
bool visit[51][51];
bool judge(int x, int y) {
  return 0 <= x && x < n && 0 <= y && y < m && s[x][y] == '#';
}
int dfs(int x, int y) {
  int x1, y1;
  int re = 1;
  for (int i = 0; i < 4; i++) {
    x1 = x + step[i][0];
    y1 = y + step[i][1];
    if (judge(x1, y1) && !visit[x1][y1]) {
      visit[x1][y1] = 1;
      re += dfs(x1, y1);
    }
  }
  return re;
}
bool pro() {
  memset(visit, 0, sizeof(visit));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (s[i][j] == '#') {
        visit[i][j] = 1;
        if (dfs(i, j) == num - 1)
          return 0;
        else
          return 1;
      }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (s[i][j] == '#') num++;
  if (num < 3)
    printf("-1\n");
  else {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (s[i][j] == '#') {
          s[i][j] = '.';
          if (pro()) {
            cout << 1 << endl;
            return 0;
          }
          s[i][j] = '#';
        }
    cout << 2 << endl;
  }
  return 0;
}
