#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e18;
const long long int mod = 1e9 + 7;
inline long long int add(long long int x, long long int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline long long int sub(long long int x, long long int y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
inline long long int mul(long long int x, long long int y) {
  return ((x % mod) * (y % mod)) % mod;
}
inline long long int power(long long int a, long long int b) {
  long long int x = 1;
  while (b) {
    if (b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline long long int inv(long long int a) { return power(a, mod - 2); }
long long int dx[4] = {0, 0, -1, 1};
long long int dy[4] = {-1, 1, 0, 0};
const long long int N = 55;
long long int n, m, cnt, tot, vis[N][N];
char a[N][N];
bool valid(long long int x, long long int y) {
  if (x >= 0 and x < n and y >= 0 and y < m and a[x][y] == '#') return true;
  return false;
}
void dfs(long long int x, long long int y) {
  vis[x][y] = 1;
  cnt++;
  for (long long int z = 0; z < 4; z++) {
    long long int xx = x + dx[z], yy = y + dy[z];
    if (valid(xx, yy) and !vis[xx][yy]) dfs(xx, yy);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '#') tot++;
    }
  }
  if (tot <= 2) {
    cout << -1;
    return 0;
  }
  bool flag = true;
  for (long long int i = 0; i < n; i++) {
    if (!flag) break;
    for (long long int j = 0; j < m; j++) {
      if (!flag) break;
      if (a[i][j] == '.') continue;
      a[i][j] = '.';
      for (long long int z = 0; z < 4; z++) {
        if (valid(i + dx[z], j + dy[z]) and flag) {
          memset(vis, 0, sizeof vis);
          cnt = 0;
          dfs(i + dx[z], j + dy[z]);
          if (cnt != (tot - 1)) {
            flag = false;
            break;
          }
        }
      }
      a[i][j] = '#';
    }
  }
  if (flag)
    cout << 2;
  else
    cout << 1;
  return 0;
}
