#include <bits/stdc++.h>
using namespace std;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
vector<long long> adj[100005], vis(100005), tin(100005), low(100005);
bitset<100005> bs;
long long timer = 0;
void dfs(long long u, long long baap = -1) {
  vis[u] = true;
  tin[u] = low[u] = timer++;
  long long child = 0;
  for (long long v : adj[u]) {
    if (v != baap) {
      if (vis[v]) {
        low[u] = min(low[u], tin[v]);
      } else {
        dfs(v, u);
        low[u] = min(low[u], low[v]);
        if (low[v] >= tin[u] && baap != -1) bs[u] = 1;
        ++child;
      }
    }
  }
  if (baap == -1 && child > 1) bs[u] = 1;
}
void find_cutpoints(long long n) {
  timer = 0;
  bs.reset();
  vis.assign(n + 1, false);
  tin.assign(n + 1, -1);
  low.assign(n + 1, -1);
  for (long long i = 1; i <= n; ++i) {
    if (!vis[i]) dfs(i);
  }
}
void solve() {
  long long n, m, k = 0;
  cin >> n >> m;
  char mat[n][m];
  long long g[n][m];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> mat[i][j];
      if (mat[i][j] == '#') g[i][j] = ++k;
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (mat[i][j] == '#') {
        if (i + 1 < n) {
          if (mat[i + 1][j] == '#') {
            adj[g[i][j]].push_back(g[i + 1][j]);
            adj[g[i + 1][j]].push_back(g[i][j]);
          }
        }
        if (i - 1 >= 0) {
          if (mat[i - 1][j] == '#') {
            adj[g[i][j]].push_back(g[i - 1][j]);
            adj[g[i - 1][j]].push_back(g[i][j]);
          }
        }
        if (j + 1 < m) {
          if (mat[i][j + 1] == '#') {
            adj[g[i][j + 1]].push_back(g[i][j]);
            adj[g[i][j]].push_back(g[i][j + 1]);
          }
        }
        if (j - 1 >= 0) {
          if (mat[i][j - 1] == '#') {
            adj[g[i][j - 1]].push_back(g[i][j]);
            adj[g[i][j]].push_back(g[i][j - 1]);
          }
        }
      }
    }
  }
  if (k <= 2) {
    cout << "-1"
         << "\n";
    return;
  }
  find_cutpoints(n);
  if (bs.count() > 0) {
    cout << '1' << "\n";
  } else
    cout << '2' << "\n";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  for (long long i = 1; i < t + 1; i++) {
    solve();
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
