#include <bits/stdc++.h>
using namespace std;
void File() {
  freopen("output.txt", "w", stdout);
  freopen("input.txt", "r", stdin);
}
void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const int oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e2 + 15;
int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, 1, -1, -1, 1, 1, -1};
int n, m;
char arr[nn][nn];
int vis[nn][nn];
bool valid(int r, int c) {
  if (r >= 0 && r < n && c >= 0 && c < m) return 1;
  return 0;
}
void connectedComponent(int r, int c) {
  if (!valid(r, c) || vis[r][c] || arr[r][c] != '#') return;
  vis[r][c] = 1;
  for (int i = 0; i < 4; i++) connectedComponent(r + dx[i], c + dy[i]);
}
int solve() {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == '#' && !vis[i][j]) {
        cnt++;
        connectedComponent(i, j);
      }
    }
  }
  return cnt;
}
int main() {
  fast();
  cin >> n >> m;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == '#') cnt++;
    }
  }
  if (cnt < 3) return cout << -1 << "\n", 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == '#') {
        arr[i][j] = '.';
        memset(vis, 0, sizeof vis);
        if (solve() > 1) return cout << 1 << "\n", 0;
        arr[i][j] = '#';
      }
    }
  }
  cout << 2 << "\n";
  return 0;
}
