#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int n, m, num = 0, f1, s1, f2, s2, dd;
bool ff = 0, ss = 0, used[100][100];
char c[100][100];
int dfs(int x, int y) {
  if (c[x][y] == '#') {
    dd++;
    used[x][y] = 1;
  }
  if (c[x + 1][y] == '#' && !used[x + 1][y]) dfs(x + 1, y);
  if (c[x - 1][y] == '#' && !used[x - 1][y]) dfs(x - 1, y);
  if (c[x][y + 1] == '#' && !used[x][y + 1]) dfs(x, y + 1);
  if (c[x][y - 1] == '#' && !used[x][y - 1]) dfs(x, y - 1);
  return dd;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i <= n + 1; i++)
    for (int j = 0; j <= m + 1; j++) c[i][j] = '.';
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
      if (c[i][j] == '#') num++;
      if (num == 1 && !ff) {
        f1 = i;
        f2 = j;
        ff = 1;
      }
      if (num == 2 && !ss) {
        s1 = i;
        s2 = j;
        ss = 1;
      }
    }
  if (num <= 2) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      bool b = 0;
      int d;
      dd = 0;
      for (int k = 0; k <= 51; k++)
        for (int l = 0; l <= 51; l++) used[k][l] = 0;
      if (c[i][j] == '#') {
        b = 1;
        c[i][j] = '.';
      }
      if (c[f1][f2] == '#')
        d = dfs(f1, f2);
      else
        d = dfs(s1, s2);
      if (d < num - 1) {
        cout << 1 << endl;
        return 0;
      }
      if (b) c[i][j] = '#';
    }
  }
  cout << 2 << endl;
  return 0;
}
