#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, d;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
char c[55][55];
bool vis[55][55];
void dfs(int x, int y) {
  vis[x][y] = 1;
  d++;
  for (int i = 0; i < 4; i++) {
    int u = x + dx[i], v = y + dy[i];
    if (u < 0 || v < 0 || u >= n || v >= m) continue;
    if (vis[u][v] || c[u][v] == '.') continue;
    dfs(u, v);
  }
}
bool ok(int x, int y) {
  c[x][y] = '.';
  d = 0;
  memset(vis, 0, sizeof(vis));
  int xx, yy;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (c[i][j] == '#') {
        xx = i;
        yy = j;
      }
  dfs(xx, yy);
  c[x][y] = '#';
  return d != cnt - 1;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++)
      if (c[i][j] == '#') cnt++;
  }
  if (cnt <= 2) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (c[i][j] == '#' && ok(i, j)) {
        cout << 1;
        return 0;
      }
  cout << 2;
  return 0;
}
