#include <bits/stdc++.h>
using namespace std;
int n, m;
int cnt;
int t;
string s;
bool a[51][51];
bool v[51][51];
int ans = 4;
int dfs(int x, int y) {
  v[x][y] = 1;
  ++t;
  if (x < n - 1 && !v[x + 1][y] && a[x + 1][y]) dfs(x + 1, y);
  if (x > 0 && !v[x - 1][y] && a[x - 1][y]) dfs(x - 1, y);
  if (y < m - 1 && !v[x][y + 1] && a[x][y + 1]) dfs(x, y + 1);
  if (y > 0 && !v[x][y - 1] && a[x][y - 1]) dfs(x, y - 1);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    for (int j = 0; j < m; ++j) {
      a[i][j] = (s[j] == '#');
      if (a[i][j]) {
        ++cnt;
      }
    }
  }
  if (cnt <= 1) {
    cout << "-1" << endl;
    return 0;
  }
  if (cnt == 2) {
    int i, j;
    for (int x = 0; x < n; ++x)
      for (int y = 0; y < m; ++y)
        if (a[x][y] == 1) {
          i = x;
          j = y;
          break;
        }
    if (i > 0 && a[i - 1][j] == 1 || i < n - 1 && a[i + 1][j] == 1 ||
        j > 0 && a[i][j - 1] == 1 || j < m - 1 && a[i][j + 1] == 1)
      cout << -1 << endl;
    else
      cout << 0 << endl;
    return 0;
  }
  bool ok = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      t = 0;
      if (a[i][j]) {
        memset(v, 0, sizeof(v));
        a[i][j] = 0;
        int p, q;
        for (p = 0; p < n; ++p)
          for (q = 0; q < m; ++q)
            if (a[p][q]) goto End;
      End:;
        dfs(p, q);
        a[i][j] = 1;
        if (t != (cnt - 1)) {
          ok = 1;
          break;
        }
      }
    }
  cout << 2 - ok << endl;
  return 0;
}
