#include <bits/stdc++.h>
using namespace std;
int R, C;
char field[52][52];
int N;
int nodes[2700];
bool vis[2700];
int deleted;
int Q[2700], Qb, Qe;
bool isnode(int u) {
  if (u < 0 || u == deleted) return false;
  int r = u / 51;
  int c = u % 51;
  if (r < 0 || r >= R || c < 0 || c >= C) return false;
  if (field[r][c] == '#') return true;
  return false;
}
void addnode(int u) {
  if (!isnode(u) || vis[u]) return;
  vis[u] = true;
  Q[Qe++] = u;
}
int count_nodes(int start) {
  int cnt = 0;
  memset(vis, 0, sizeof vis);
  Qb = 0, Qe = 1;
  Q[0] = start;
  vis[start] = true;
  while (Qb < Qe) {
    cnt += 1;
    int u = Q[Qb++];
    addnode(u - 51);
    addnode(u + 51);
    addnode(u - 1);
    addnode(u + 1);
  }
  return cnt;
}
int main() {
  scanf("%d %d", &R, &C);
  for (int r = 0; r < R; ++r) {
    scanf("%s", field[r]);
    for (int c = 0; c < C; ++c) {
      if (field[r][c] == '.') continue;
      nodes[N++] = 51 * r + c;
    }
  }
  if (N <= 2) {
    puts("-1");
    return 0;
  }
  int s = nodes[0];
  int mn = 0;
  if (isnode(s + 1)) mn += 1;
  if (isnode(s + 51)) mn += 1;
  for (int i = 0; i < N; ++i) {
    deleted = nodes[i];
    int cnt = 0;
    if (isnode(deleted - 1))
      cnt = count_nodes(deleted - 1);
    else if (isnode(deleted + 1))
      cnt = count_nodes(deleted + 1);
    else if (isnode(deleted - 51))
      cnt = count_nodes(deleted - 51);
    else if (isnode(deleted + 51))
      cnt = count_nodes(deleted + 51);
    if (cnt != N - 1) {
      mn = 1;
      break;
    }
  }
  printf("%d\n", mn);
  return 0;
}
