#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2555;
struct ver {
  int x, y;
  vector<int> g;
};
int n, m;
vector<ver> a;
ver tadd;
int timer, tin[MAXN], fup[MAXN];
bool used[MAXN];
void panic(int k) {
  cout << 1;
  exit(0);
}
void dfs(int v, int p) {
  int ch = 0;
  used[v] = true;
  tin[v] = timer++;
  fup[v] = tin[v];
  for (int i = 0; i < a[v].g.size(); i++) {
    int to = a[v].g[i];
    if (to == p) continue;
    if (used[to])
      fup[v] = min(fup[v], tin[to]);
    else {
      dfs(to, v);
      fup[v] = min(fup[v], fup[to]);
      if (p == -1)
        ch++;
      else if (fup[to] >= tin[v])
        panic(v);
    }
  }
  if (p == -1 && ch > 1) panic(v);
}
int main() {
  cin >> n >> m;
  scanf("%*c");
  tadd.g.clear();
  timer = 0;
  char r;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%c", &r);
      if (r == '#') {
        tadd.x = i;
        tadd.y = j;
        a.push_back(tadd);
      }
    }
    scanf("%*c");
  }
  n = a.size();
  memset(used, 0, sizeof(used));
  if (n <= 2) {
    cout << -1;
    exit(0);
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int sum = abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);
      if (sum == 1) {
        a[i].g.push_back(j);
        a[j].g.push_back(i);
      }
    }
  }
  dfs(0, -1);
  cout << 2;
  return 0;
}
