#include <bits/stdc++.h>
using namespace std;
char a[100][100];
vector<int> v[3000];
int id[3000], low[3000];
int cnt, cc, idx;
bool ok;
void dfs(int r, int p) {
  id[r] = low[r] = ++cnt;
  for (int i = 0; i < v[r].size(); i++) {
    if (v[r][i] == p) continue;
    if (id[v[r][i]]) {
      low[r] = min(low[r], id[v[r][i]]);
    } else {
      dfs(v[r][i], r);
      low[r] = min(low[r], low[v[r][i]]);
      if (r == idx) cc++;
      if (low[v[r][i]] >= id[r] && r != idx) {
        ok = 1;
        return;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int c = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '#') c++;
    }
  }
  if (c <= 2) {
    cout << -1;
    return 0;
  }
  int o[100][100];
  int r = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#' && !idx) idx = r;
      o[i][j] = r;
      r++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] != '#') continue;
      if (i && a[i - 1][j] == '#') v[o[i][j]].push_back(o[i - 1][j]);
      if (j && a[i][j - 1] == '#') v[o[i][j]].push_back(o[i][j - 1]);
      if (j + 1 != m && a[i][j + 1] == '#') v[o[i][j]].push_back(o[i][j + 1]);
      if (i + 1 != n && a[i + 1][j] == '#') v[o[i][j]].push_back(o[i + 1][j]);
    }
  }
  dfs(idx, 0);
  if (cc > 1 || ok)
    cout << 1;
  else
    cout << 2;
  return 0;
}
