#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long hell = round(1e18);
long long dfs(vector<vector<long long> >& v, long long m, long long n,
              long long cx, long long cy) {
  v[cx][cy] = -1;
  vector<pair<long long, long long> > b({{-1, 0}, {1, 0}, {0, 1}, {0, -1}});
  for (long long i = 0; i < 4; i++) {
    long long nx = cx + b[i].first;
    long long ny = cy + b[i].second;
    if ((v[nx][ny]) == 1) {
      dfs(v, m, n, nx, ny);
    }
  }
}
long long check(vector<vector<long long> > v, long long m, long long n,
                long long cx, long long cy) {
  vector<pair<long long, long long> > b({{-1, 0}, {1, 0}, {0, 1}, {0, -1}});
  for (long long i = 0; i < 4; i++) {
    long long nx = cx + b[i].first;
    long long ny = cy + b[i].second;
    if (v[nx][ny] == 1) {
      cx = nx;
      cy = ny;
      break;
    }
  }
  dfs(v, m, n, cx, cy);
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      if (v[i][j] == 1) return 0;
    }
  }
  return 1;
}
signed solve() {
  long long m, n;
  cin >> n >> m;
  vector<vector<long long> > v(n + 2, vector<long long>(m + 2, 2));
  long long s = 0;
  long long cur;
  long long cx, cy;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      char ch;
      cin >> ch;
      v[i][j] = (ch == '#') ? 1 : 0;
      s += v[i][j];
      if (v[i][j] == 1) {
        cx = i;
        cy = j;
      }
    }
  }
  if (s == 1 || s == 2)
    cout << -1;
  else if (s == 3)
    cout << 1;
  else {
    for (long long i = 1; i < n + 1; i++) {
      for (long long j = 1; j < m + 1; j++) {
        if (v[i][j] == 1) {
          v[i][j] = 0;
          long long x = check(v, m, n, i, j);
          if (x == 0) {
            cout << 1;
            return 0;
          }
          v[i][j] = 1;
        }
      }
    }
    cout << 2;
  }
  return 0;
}
signed main() {
  long long t = 1;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  while (t--) {
    solve();
  }
  return 0;
}
