#include <bits/stdc++.h>
double const PI = 4 * atan(1);
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};
using namespace std;
void OPEN() {
  freopen("A.in", "r", stdin);
  freopen("A.out", "w", stdout);
}
int n, m, flag[55][55];
string s[55], a[55];
void go(int u, int v) {
  if (u >= 0 && u < n && v >= 0 && v < m && a[u][v] == '#' && flag[u][v] == 0)
    ;
  else
    return;
  flag[u][v] = 1;
  for (int t = 0; t < 4; t++) go(u + dx[t], v + dy[t]);
}
bool duyet() {
  int res = 0;
  memset(flag, 0, sizeof(flag));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] == '#' && !flag[i][j]) {
        go(i, j);
        res++;
      }
  return res == 1;
}
int main() {
  int sum = 0;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < m; j++) {
      a[i].push_back(s[i][j]);
      if (s[i][j] == '#') sum++;
    }
  }
  if (sum == 1 || sum == 2) {
    cout << "-1";
    return 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (s[i][j] == '#') {
        a[i][j] = '.';
        if (!duyet()) {
          cout << "1";
          return 0;
        }
        a[i][j] = '#';
      }
  cout << "2";
}
