#include <bits/stdc++.h>
using namespace std;
vector<bool> visited;
vector<int> tin, low;
int timer;
bool glo = false;
void dfs(int v, int p, vector<vector<int>> &adj) {
  visited[v] = true;
  tin[v] = low[v] = timer++;
  int children = 0;
  for (int to : adj[v]) {
    if (to == p) continue;
    if (visited[to]) {
      low[v] = min(low[v], tin[to]);
    } else {
      dfs(to, v, adj);
      low[v] = min(low[v], low[to]);
      if (low[to] >= tin[v] && p != -1) {
        glo = true;
      }
      ++children;
    }
  }
  if (p == -1 && children > 1) {
    glo = true;
  }
}
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1};
bool esValido(int x, int y, int n, int m) {
  return (0 <= x && x < n && 0 <= y && y < m);
}
bool find_cutpoints(vector<vector<int>> &adj) {
  int n = adj.size();
  timer = 0;
  visited.assign(n, false);
  tin.assign(n, -1);
  low.assign(n, -1);
  for (int i = 0; i < n; ++i) {
    if (!visited[i]) dfs(i, -1, adj);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> mat(n);
  int cant = 0;
  map<pair<int, int>, int> id;
  map<int, pair<int, int>> di;
  int chequito = 0;
  for (int i = 0; i < int(n); i++) {
    cin >> mat[i];
    for (int j = 0; j < int(m); j++) {
      if (mat[i][j] == '#') {
        cant++;
        id[{i, j}] = chequito;
        chequito++;
      }
    }
  }
  if (cant <= 2) {
    cout << -1 << endl;
    return 0;
  }
  vector<vector<int>> adj(cant);
  for (int i = 0; i < int(n); i++) {
    for (int j = 0; j < int(m); j++) {
      if (mat[i][j] == '#') {
        for (int k = 0; k < int(4); k++) {
          int x = i + dx[k], y = j + dy[k];
          if (esValido(x, y, n, m) && mat[x][y] == '#') {
            adj[id[{i, j}]].push_back(id[{x, y}]);
          }
        }
      }
    }
  }
  find_cutpoints(adj);
  if (glo) {
    cout << 1 << endl;
  } else
    cout << 2 << endl;
}
