#include <bits/stdc++.h>
using namespace std;
int n, m, tot = 0, cnt = 0;
vector<string> v;
vector<pair<int, int> > s = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool vis[55][55];
void DFS(int a, int b) {
  if (a < 0 || a >= n || b < 0 || b >= m) return;
  if (v[a][b] == '.' || vis[a][b]) return;
  cnt++;
  vis[a][b] = true;
  for (int i = 0; i < (4); i++) {
    DFS(a + s[i].first, b + s[i].second);
  }
}
bool Test(int a, int b) {
  if (v[a][b] == '.') return false;
  v[a][b] = '.';
  for (int i = 0; i < (4); i++) {
    cnt = 0;
    memset(vis, false, sizeof(vis));
    DFS(a + s[i].first, b + s[i].second);
    if (cnt && cnt != tot - 1) return true;
  }
  v[a][b] = '#';
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  v = vector<string>(n);
  for (int i = 0; i < (n); i++) {
    cin >> v[i];
    for (int j = 0; j < (m); j++) tot += (v[i][j] == '#');
  }
  if (tot < 3) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (m); j++) {
      if (Test(i, j)) {
        cout << 1 << endl;
        return 0;
      }
    }
  }
  cout << 2 << endl;
}
