#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65536535")
using namespace std;
char ss[51][51];
char s[51];
int n, m;
bool was[51][51];
int dfs(int x, int y) {
  if (x < 0 || y < 0 || x >= n || y >= m || was[x][y] || ss[x][y] == '.')
    return 0;
  was[x][y] = true;
  int count = 1;
  for (int dx = -1; dx <= 1; dx++) {
    for (int dy = -1; dy <= 1; dy++) {
      if (abs(dx) + abs(dy) != 1) continue;
      count += dfs(x + dx, y + dy);
    }
  }
  return count;
}
bool check(int countt, int x0, int y0, int mins) {
  memset(was, 0, sizeof(was));
  int gg = dfs(x0, y0);
  return gg != countt - mins;
}
int main() {
  vector<pair<int, int> > pt;
  gets(s);
  sscanf(s, "%d %d", &n, &m);
  int countt = 0;
  for (int i = 0; i < n; i++) {
    gets(ss[i]);
    for (int j = 0; j < strlen(ss[i]); j++) {
      if (ss[i][j] == '#') {
        ++countt;
        pt.push_back(make_pair(i, j));
      }
    }
  }
  int answ = -1;
  int sz = pt.size();
  if (sz < 3) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < sz; i++) {
    ss[pt[i].first][pt[i].second] = '.';
    pair<int, int> start;
    if (i == 0)
      start = pt[1];
    else
      start = pt[0];
    if (check(countt, start.first, start.second, 1)) {
      printf("1\n");
      return 0;
    }
    ss[pt[i].first][pt[i].second] = '#';
  }
  for (int i = 0; i < sz; i++) {
    for (int j = i + 1; j < sz; j++) {
      ss[pt[i].first][pt[i].second] = '.';
      ss[pt[j].first][pt[j].second] = '.';
      int k;
      for (k = 0;; k++) {
        if (k != i && k != j) break;
      }
      pair<int, int> start;
      if (check(countt, start.first, start.second, 2)) {
        printf("2\n");
        return 0;
      }
      ss[pt[i].first][pt[i].second] = '#';
      ss[pt[j].first][pt[j].second] = '#';
    }
  }
  printf("-1\n");
}
