#include <bits/stdc++.h>
using namespace std;
char a[51][51];
int doneat[51][51];
long long tin[51][51];
long long low[51][51];
long long timee;
int n, m;
int ap;
void dfs(int i, int j, int pi, int pj) {
  if (doneat[i][j]) return;
  tin[i][j] = low[i][j] = timee++;
  doneat[i][j] = true;
  int child = 0;
  if (i + 1 < n && a[i + 1][j] == '#' && !(i + 1 == pi && j == pj)) {
    if (doneat[i + 1][j])
      low[i][j] = min(low[i][j], tin[i + 1][j]);
    else {
      dfs(i + 1, j, i, j);
      low[i][j] = min(low[i][j], low[i + 1][j]);
      if (low[i + 1][j] >= tin[i][j] && !(pi == -1 && pj == -1)) ap = 1;
      child++;
    }
  }
  if (i - 1 >= 0 && a[i - 1][j] == '#' && !(i - 1 == pi && j == pj)) {
    if (doneat[i - 1][j])
      low[i][j] = min(low[i][j], tin[i - 1][j]);
    else {
      dfs(i - 1, j, i, j);
      low[i][j] = min(low[i][j], low[i - 1][j]);
      if (low[i - 1][j] >= tin[i][j] && !(pi == -1 && pj == -1)) ap = 1;
      child++;
    }
  }
  if (j - 1 >= 0 && a[i][j - 1] == '#' && !(i == pi && j - 1 == pj)) {
    if (doneat[i][j - 1])
      low[i][j] = min(low[i][j], tin[i][j - 1]);
    else {
      dfs(i, j - 1, i, j);
      low[i][j] = min(low[i][j], low[i][j - 1]);
      if (low[i][j - 1] >= tin[i][j] && !(pi == -1 && pj == -1)) ap = 1;
      child++;
    }
  }
  if (j + 1 < m && a[i][j + 1] == '#' && !(i == pi && j + 1 == pj)) {
    if (doneat[i][j + 1])
      low[i][j] = min(low[i][j], tin[i][j + 1]);
    else {
      dfs(i, j + 1, i, j);
      low[i][j] = min(low[i][j], low[i][j + 1]);
      if (low[i][j + 1] >= tin[i][j] && !(pi == -1 && pj == -1)) ap = 1;
      child++;
    }
  }
  if (pi == -1 && pj == -1 && child > 1) ap = 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  long long cnt = 0;
  long long ti, tj;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '#') {
        cnt++;
        ti = i;
        tj = j;
      }
      doneat[i][j] = 0;
    }
  ap = 0;
  timee = 0;
  int f = 1;
  if (!cnt) {
    cout << -1;
    f = 0;
  } else
    dfs(ti, tj, -1, -1);
  if (f) {
    if (ap)
      cout << 1;
    else if (cnt < 3)
      cout << -1;
    else
      cout << 2;
  }
  return 0;
}
