#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int n, m;
bool valid(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; }
void dfs(vector<vector<int>>& vis, vector<string>& v, int& cnt, int i, int j) {
  vis[i][j] = 1;
  cnt++;
  for (int k = 0; k < 4; k++) {
    int x = i + dx[k];
    int y = j + dy[k];
    if (valid(x, y) && v[x][y] == '#' && vis[x][y] == 0) {
      dfs(vis, v, cnt, x, y);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int cnt = 0;
  bool ok = false;
  cin >> n >> m;
  vector<string> v(n);
  vector<vector<int>> vis(n, vector<int>(m, 0));
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] == '#') {
        cnt++;
      }
    }
  }
  if (cnt <= 2) {
    cout << -1 << '\n';
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] == '#') {
        v[i][j] = '.';
        int c = 0;
        for (int k = 0; k < 4; k++) {
          int x = i + dx[k];
          int y = j + dy[k];
          if (valid(x, y) && v[x][y] == '#') {
            dfs(vis, v, c, x, y);
            break;
          }
        }
        if (c < cnt - 1) {
          ok = true;
        }
        vis = vector<vector<int>>(n, vector<int>(m, 0));
        v[i][j] = '#';
      }
    }
  }
  if (ok) {
    cout << 1 << '\n';
  } else {
    cout << 2 << '\n';
  }
  return 0;
}
