#include <bits/stdc++.h>
using namespace std;
int gr[55][55];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
bool vis[55][55];
int n, m;
bool val(int x, int y) {
  if (x > 0 && y > 0 && x <= n && y <= m) return true;
  return false;
}
int dfs(int x, int y) {
  if (!val(x, y) || vis[x][y] || (gr[x][y] == 0)) {
    return 0;
  }
  vis[x][y] = 1;
  for (int k = 0; k < 4; k++) dfs(x + dx[k], y + dy[k]);
  return 1;
}
int main() {
  cin >> n >> m;
  string x;
  int co = 0;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    for (int j = 0; j < m; j++) {
      if (x[j] == '#') {
        co++;
        gr[i][j + 1] = 1;
      } else
        gr[i][j + 1] = 0;
    }
  }
  if (co <= 2) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (gr[i][j]) {
        gr[i][j] = 0;
        memset(vis, 0, sizeof(vis));
        int g = 0;
        for (int k = 0; k < 4; k++) {
          g += dfs(i + dx[k], j + dy[k]);
        }
        if (g > 1) {
          cout << 1 << endl;
          return 0;
        }
        gr[i][j] = 1;
      } else
        gr[i][j] = 0;
    }
  }
  cout << 2 << endl;
  return 0;
}
