#include <bits/stdc++.h>
using namespace std;
const int N = 2e2 + 5;
char s[N][N];
int n, m, cnt = 0, vis[N][N];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
void dfs(int x, int y) {
  vis[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int a = x + dx[i], b = y + dy[i];
    if (a >= 1 && a <= n && b >= 1 && b <= m && s[a][b] == '#') {
      if (!vis[a][b]) dfs(a, b);
    }
  }
}
int main() {
  bool flag = true;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> s[i] + 1;
  int res = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '.') continue;
      cnt++;
      s[i][j] = '.';
      int tot = 0;
      memset(vis, 0, sizeof(vis));
      for (int a = 1; a <= n; a++) {
        for (int b = 1; b <= m; b++) {
          if (s[a][b] == '.') continue;
          if (!vis[a][b]) {
            tot++;
            dfs(a, b);
            if (tot > 1) res = 1;
          }
        }
      }
      s[i][j] = '#';
    }
  }
  if (res == -1 && cnt > 2) res = 2;
  cout << res;
  return 0;
}
