#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, m;
string a[100];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
bool used[100][100];
bool ok(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
void dfs(int x, int y) {
  if (!ok(x, y)) return;
  if (a[x][y] != '#') return;
  if (used[x][y]) return;
  used[x][y] = true;
  for (int d = 0; d < 4; d++) {
    dfs(x + dx[d], y + dy[d]);
  }
}
bool is_connected() {
  memset(used, 0, sizeof used);
  int x = -1, y = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#') {
        x = i;
        y = j;
      }
    }
  }
  if (x == -1 && y == -1) return false;
  dfs(x, y);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] == '#' && !used[i][j]) return false;
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int cnt = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cnt += (a[i][j] == '#');
  if (cnt < 3) return cout << -1 << endl, 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#') {
        a[i][j] = '.';
        if (!is_connected()) {
          cout << 1 << endl;
          return 0;
        }
        a[i][j] = '#';
      }
    }
  }
  cout << 2 << endl;
  return 0;
}
