#include <bits/stdc++.h>
using namespace std;
int n, m, nodes = 0;
char a[51][51];
bool v[51][51];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
vector<pair<int, int> > np;
int dfs(int r, int c) {
  if (r >= n || c >= m || r < 0 || c < 0 || v[r][c] || a[r][c] == '.') return 0;
  int s = 1;
  v[r][c] = 1;
  for (int i = 0; i < 4; i++) {
    s += dfs(r + dx[i], c + dy[i]);
  }
  return s;
}
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%c", &a[i][j]);
      if (a[i][j] == '#') {
        nodes++;
        np.push_back(make_pair(i, j));
      }
      scanf("\n");
    }
  }
  if (nodes == 0 || nodes == 1 || nodes == 2) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < np.size(); i++) {
    memset(v, 0, sizeof v);
    a[np[i].first][np[i].second] = '.';
    int r, c;
    if (i == 0) {
      r = np[i + 1].first;
      c = np[i + 1].second;
    } else {
      r = np[i - 1].first;
      c = np[i - 1].second;
    }
    int x = dfs(r, c);
    if (x != nodes - 1) {
      puts("1");
      return 0;
    }
    a[np[i].first][np[i].second] = '#';
  }
  puts("2");
  return 0;
}
