#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long int ans = 0;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  ans += a / b;
  return gcd(b, a % b);
}
long long int mod = 1000000007;
long long int binpower(long long int a, long long int b) {
  long long int ans = 1;
  while (b > 0) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
bool isPrime(int n) {
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) return false;
  }
  return true;
}
long long int gprime[10000001];
void grsieve() {
  gprime[1] = 1;
  gprime[0] = 1;
  for (long long int i = 2; i < 10000001; ++i) {
    if (gprime[i] == 0) {
      for (long long int j = i; j < 10000001; j += i) gprime[j] = i;
    }
  }
}
int n, m;
bool visited[51][51];
string s[51];
void dfs(int i, int j) {
  visited[i][j] = true;
  if (i < n - 1 && s[i + 1][j] == '#' && !visited[i + 1][j]) dfs(i + 1, j);
  if (j < m - 1 && s[i][j + 1] == '#' && !visited[i][j + 1]) dfs(i, j + 1);
  if (i > 0 && s[i - 1][j] == '#' && !visited[i - 1][j]) dfs(i - 1, j);
  if (j > 0 && s[i][j - 1] == '#' && !visited[i][j - 1]) dfs(i, j - 1);
  return;
}
int main() {
  int test = 1;
  while (test--) {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> s[i];
    vector<pair<int, int> > v;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (s[i][j] == '#') v.push_back({i, j});
      }
    }
    if (v.size() == 0 || v.size() == 1 || v.size() == 2) {
      cout << -1;
      exit(0);
    }
    int flag = 0;
    for (int i = 0; i < v.size(); i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < m; k++) visited[j][k] = false;
      }
      s[v[i].first][v[i].second] = '.';
      int curri, currj;
      if (i == 0) {
        curri = v[1].first;
        currj = v[1].second;
      } else {
        curri = v[0].first;
        currj = v[0].second;
      }
      dfs(curri, currj);
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < m; k++) {
          if (s[j][k] == '#' && !visited[j][k]) {
            cout << 1;
            exit(0);
          }
        }
      }
      s[v[i].first][v[i].second] = '#';
    }
    cout << 2;
  }
  return 0;
}
