#include <bits/stdc++.h>
using namespace std;
bool c[50 + 5][50 + 5];
bool t[50 + 5][50 + 5];
pair<int, int> mo[4];
int td = 0;
pair<int, int> a1;
pair<int, int> a2;
inline int dfs(int x, int y) {
  int ret = 1;
  c[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int newx = x + mo[i].first, newy = y + mo[i].second;
    if (t[newx][newy] && (!c[newx][newy])) ret += dfs(newx, newy);
  }
  return ret;
}
inline bool isconnected() {
  if (!c[a1.first][a1.second])
    return (td - 1 == dfs(a1.first, a1.second));
  else
    return (td - 1 == dfs(a2.first, a2.second));
}
int main() {
  memset(c, 0, sizeof c);
  memset(t, 0, sizeof t);
  mo[0].first = mo[1].first = mo[2].second = mo[3].second = 0;
  mo[0].second = mo[2].first = 1;
  mo[1].second = mo[3].first = -1;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    string st;
    cin >> st;
    for (int j = 1; j <= m; ++j) {
      t[i][j] = (st[j - 1] == '#');
      if (t[i][j]) {
        td++;
        if (td == 1) {
          a1.first = i;
          a1.second = j;
        } else if (td == 2) {
          a2.first = i;
          a2.second = j;
        }
      }
    }
  }
  if (td < 3) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (t[i][j]) {
        memset(c, 0, sizeof c);
        c[i][j] = true;
        if (!isconnected()) {
          cerr << i << " " << j << endl;
          cout << 1 << endl;
          return 0;
        }
      }
    }
  }
  cout << 2 << endl;
  return 0;
}
