#include <bits/stdc++.h>
using namespace std;
int const N = 70;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
char s[N][N];
int vis[N][N];
int n, m;
int dfs(int x, int y) {
  if (s[x][y] != '#' || vis[x][y]) return 0;
  vis[x][y] = 1;
  for (int i = 0; i < (4); i++) dfs(x + dx[i], y + dy[i]);
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (n); i++) scanf("%s", s[i]);
  int cnt = 0;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) {
      if (s[i][j] == '.') continue;
      cnt++;
      s[i][j] = '.';
      int k = 0;
      memset(vis, 0, sizeof(vis));
      for (int d = 0; d < (4); d++) k += dfs(i + dx[d], j + dy[d]);
      if (k > 1) {
        puts("1");
        return 0;
      }
      s[i][j] = '#';
    }
  printf("%d\n", cnt > 2 ? 2 : -1);
}
