#include <bits/stdc++.h>
const int inf = 0x7FFFFFFF;
using namespace std;
char field[51][51];
int N, M, num;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
bool mark[51][51];
int check() {
  int ret = 1;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++)
      if (field[i][j] == '#' && !mark[i][j]) {
        return 2;
      }
  return ret;
}
void dfs(int x, int y) {
  if (x >= 0 && x < N && y >= 0 && y < M) {
    if (mark[x][y] || field[x][y] == '.') return;
    mark[x][y] = true;
    for (int i = 0; i < 4; i++) dfs(x + dx[i], y + dy[i]);
  }
}
int go(int x, int y) {
  if (x == -1) return -1;
  memset(mark, false, sizeof(mark));
  dfs(x, y);
  int res = check();
  if (res == 1 && num < 3) return -1;
  if (res == 2) return 0;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++)
      if (field[i][j] == '#') {
        field[i][j] = '.';
        memset(mark, false, sizeof(mark));
        dfs(x, y);
        if (check() == 2) return 1;
        field[i][j] = '#';
        x = i, y = j;
      }
  return 2;
}
int main() {
  int x = -1, y;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%s", field[i]);
    for (int j = 0; j < M; j++)
      if (field[i][j] == '#') {
        x = i, y = j;
        num++;
      }
  }
  int ans = go(x, y);
  printf("%d\n", ans);
  return 0;
}
