#include <bits/stdc++.h>
using namespace std;
int n, m, count1 = 0, count2 = 0, min1 = 1e5;
bool used[2501];
vector<int> a[2501];
char c[51][51];
int b[51][51];
void dfs(int x, int except) {
  used[x] = true;
  for (int i = 0; i < a[x].size(); i++) {
    if (used[a[x][i]] || a[x][i] == except) {
      continue;
    }
    dfs(a[x][i], except);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
      if (c[i][j] == '#') {
        count1++;
        b[i][j] = count1;
      }
    }
  }
  if (count1 < 3) {
    cout << -1 << endl;
    return 0;
  }
  count1 = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (c[i][j] != '#') {
        continue;
      }
      count1++;
      if (i > 1) {
        if (c[i - 1][j] == '#') {
          a[count1].push_back(b[i - 1][j]);
        }
      }
      if (j > 1) {
        if (c[i][j - 1] == '#') {
          a[count1].push_back(b[i][j - 1]);
        }
      }
      if (i < n) {
        if (c[i + 1][j] == '#') {
          a[count1].push_back(b[i + 1][j]);
        }
      }
      if (j < m) {
        if (c[i][j + 1] == '#') {
          a[count1].push_back(b[i][j + 1]);
        }
      }
    }
  }
  for (int k = 1; k <= count1; k++) {
    fill(used, used + 2501, false);
    count2 = 0;
    for (int i = 1; i <= count1; i++) {
      if (used[i] || k == i) {
        continue;
      }
      dfs(i, k);
      count2++;
    }
    if (count2 > 1) {
      cout << 1 << endl;
      return 0;
    }
  }
  for (int i = 1; i <= count1; i++) {
    if (a[i].size() < min1 && a[i].size() > 0) {
      min1 = a[i].size();
    }
  }
  cout << min1 << endl;
  return 0;
}
