#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> grid(n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> grid[i];
    cnt += count(begin(grid[i]), end(grid[i]), '#');
  }
  if (cnt <= 2) {
    cout << -1 << '\n';
    return (0);
  }
  vector<vector<int>> G(n * m);
  vector<int> squares;
  {
    vector<int> dr = {1, -1, 0, 0};
    vector<int> dc = {0, 0, 1, -1};
    for (int r = 0; r < n; r++) {
      for (int c = 0; c < m; c++) {
        if (not(grid[r][c] == '#')) continue;
        int u = r * m + c;
        squares.push_back(u);
        for (int d = 0; d < 4; d++) {
          int nr = r + dr[d];
          int nc = c + dc[d];
          int v = nr * m + nc;
          if (not(0 <= min(nr, nc) and nr < n and nc < m and
                  grid[nr][nc] == '#'))
            continue;
          G[u].push_back(v);
        }
      }
    }
  }
  vector<bool> vis(n * m);
  function<void(int, int)> dfs = [&](int u, int b) {
    vis[u] = true;
    if (u == b) return;
    for (int v : G[u])
      if (not vis[v]) dfs(v, b);
  };
  for (int u : squares) {
    int root = (squares.front() == u) ? squares.back() : squares.front();
    fill(begin(vis), end(vis), false);
    dfs(root, u);
    bool ok = true;
    for (int v : squares) ok &= vis[v];
    if (not ok) {
      cout << 1 << '\n';
      return (0);
    }
  }
  cout << 2 << '\n';
  return (0);
}
