#include <bits/stdc++.h>
using namespace std;
int N, M;
bool matr[50][50];
bool was[50][50];
int dirs[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int f(int i, int j) {
  was[i][j] = true;
  int res = 1;
  for (int d = 0; d < 4; d++) {
    int ii = i + dirs[d][0];
    int jj = j + dirs[d][1];
    if (ii >= 0 && ii < N && jj >= 0 && jj < M && matr[ii][jj] && !was[ii][jj])
      res += f(ii, jj);
  }
  return res;
}
int main() {
  scanf("%d%d", &N, &M);
  int allCnt = 0;
  for (int i = 0; i < N; i++) {
    char s[100];
    scanf("%s", s);
    for (int j = 0; j < M; j++) {
      matr[i][j] = s[j] == '#';
      if (matr[i][j]) allCnt++;
    }
  }
  if (allCnt < 2) {
    printf("-1\n");
    return 0;
  }
  memset(was, 0, 50 * 50);
  bool connected = true;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++)
      if (connected && matr[i][j] && !was[i][j]) {
        int a = f(i, j);
        if (a != allCnt) connected = false;
      }
  if (!connected)
    printf("0\n");
  else {
    if (allCnt == 2) {
      printf("-1\n");
      return 0;
    }
    bool one = false;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < M; j++)
        if (!one && matr[i][j]) {
          matr[i][j] = false;
          int xx = -1;
          int yy = -1;
          for (int d = 0; d < 4; d++) {
            int ii = i + dirs[d][0];
            int jj = j + dirs[d][1];
            if (ii >= 0 && ii < N && jj >= 0 && jj < M && matr[ii][jj]) {
              xx = ii;
              yy = jj;
              break;
            }
          }
          memset(was, 0, 50 * 50);
          int a = f(xx, yy);
          if (a + 1 != allCnt) one = true;
          matr[i][j] = true;
        }
    if (one)
      printf("1\n");
    else
      printf("2\n");
  }
  return 0;
}
