#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
#pragma pack(1)
using namespace std;
const int dx[4] = {1, 0, 0, -1};
const int dy[4] = {0, 1, -1, 0};
bool B[53][53], used[53][53];
int n = 0;
struct Point {
  int x, y;
  Point(int i, int j) {
    x = i;
    y = j;
  }
};
queue<Point> my_que;
vector<Point> Diez;
int main() {
  int n, m;
  int count_DIES = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    char c = getchar();
    for (int j = 0; j < m; j++) {
      char ch = getchar();
      while (ch == 10 || ch == 13) ch = getchar();
      if (ch == '#') {
        count_DIES++;
        B[i][j] = true;
        Diez.push_back(Point(i, j));
      } else
        B[i][j] = false;
    }
  }
  if (count_DIES < 3) {
    printf("-1");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (B[i][j]) {
        B[i][j] = false;
        Point tmp = Diez[0];
        if (tmp.x == i && tmp.y == j) tmp = Diez[1];
        memset(used, 0, sizeof(used));
        used[tmp.x][tmp.y] = true;
        my_que.push(tmp);
        int count_while = 0;
        while (!my_que.empty()) {
          tmp = my_que.front();
          my_que.pop();
          for (int l = 0; l < 4; l++) {
            int tx = tmp.x + dx[l];
            int ty = tmp.y + dy[l];
            if (tx >= 0 && tx < n && ty >= 0 && ty < m && B[tx][ty] &&
                !used[tx][ty]) {
              used[tx][ty] = true;
              my_que.push(Point(tx, ty));
            }
          }
          count_while++;
        }
        if (count_while < count_DIES - 1) {
          printf("1");
          return 0;
        }
        B[i][j] = true;
      }
    }
  }
  printf("2");
  return 0;
}
