#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e6 + 44;
const int X[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int Y[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int mod = 998244353;
const long double INF = 1e18;
std::vector<int> g[N];
bool used[N], c[66][66];
int f[N], tin[N], timer, mn = 4;
void dfs(int v, int p = -1) {
  used[v] = 1;
  int c = 0;
  tin[v] = f[v] = timer++;
  for (int to : g[v])
    if (to != p) {
      mn = min(mn, (int)g[v].size());
      if (!used[to]) {
        dfs(to, v);
        ++c;
        f[v] = min(f[v], f[to]);
        if (p != -1 && tin[v] <= f[to]) cout << "1", exit(0);
      } else {
        f[v] = min(f[v], tin[to]);
      }
    }
  if (p == -1 && c > 1) cout << "1", exit(0);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  int cnt = 0, root = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      char cc;
      cin >> cc;
      if (cc == '#')
        c[i][j] = 1;
      else
        continue;
      root = i * m + j, cnt++;
      if (i > 0 && c[i - 1][j])
        g[i * m + j].push_back(i * m + j - m),
            g[i * m + j - m].push_back(i * m + j);
      if (j > 0 && c[i][j - 1])
        g[i * m + j].push_back(i * m + j - 1),
            g[i * m + j - 1].push_back(i * m + j);
    }
  }
  if (cnt < 3) return cout << "-1", 0;
  dfs(root);
  cout << mn;
}
