#include <bits/stdc++.h>
using namespace std;
int dr[] = {-1, 0, 0, +1};
int dc[] = {0, -1, +1, 0};
int R, C;
char B[52][52];
int vis[52][52];
int nodes;
void dfs(int r, int c) {
  vis[r][c]++;
  ++nodes;
  for (int k = 0, _n = (4); k < _n; ++k) {
    int nr = r + dr[k], nc = c + dc[k];
    if (B[nr][nc] != '#' || vis[nr][nc]) continue;
    dfs(nr, nc);
  }
}
int main(int argc, char* argv[]) {
  scanf("%d %d", &R, &C);
  memset(B, '.', sizeof(B));
  for (int r = (1), _b = (R); r <= _b; ++r) {
    scanf("%s", B[r] + 1);
    B[r][C + 1] = '.';
  }
  int cnt = 0;
  for (int r = (1), _b = (R); r <= _b; ++r)
    for (int c = (1), _b = (C); c <= _b; ++c)
      if (B[r][c] == '#') ++cnt;
  if (cnt <= 2) {
    puts("-1");
    return 0;
  }
  int min_deg = cnt;
  for (int r = (1), _b = (R); r <= _b; ++r)
    for (int c = (1), _b = (C); c <= _b; ++c) {
      if (B[r][c] != '#') continue;
      int deg = 0;
      for (int k = 0, _n = (4); k < _n; ++k) {
        int nr = r + dr[k], nc = c + dc[k];
        if (B[nr][nc] == '#') ++deg;
      }
      min_deg = min(min_deg, deg);
    }
  for (int r = (1), _b = (R); r <= _b; ++r)
    for (int c = (1), _b = (C); c <= _b; ++c) {
      if (B[r][c] == '#') {
        nodes = 0;
        memset(vis, 0, sizeof(vis));
        B[r][c] = '.';
        for (int k = 0, _n = (4); k < _n; ++k) {
          int nr = r + dr[k], nc = c + dc[k];
          if (B[nr][nc] == '#') {
            dfs(nr, nc);
            if (nodes + 1 != cnt) {
              fprintf(stderr, "(%d, %d) nodes = %d\n", r, c, nodes);
              puts("1");
              return 0;
            }
            break;
          }
        }
        B[r][c] = '#';
      }
    }
  printf("%d\n", min_deg);
  return 0;
}
