#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
template <class T>
T SQR(const T &a) {
  return a * a;
}
char B[52][52];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
bool check(char A[52][52], int n, int m, int x, int y) {
  memcpy(B, A, sizeof(char) * 52 * 52);
  B[x][y] = '.';
  int sti, stj = -1;
  for (int i = (1), ei = (n + 1); i < ei; i++)
    for (int j = (1), ej = (m + 1); j < ej; j++)
      if (B[i][j] == '#') {
        sti = i;
        stj = j;
      }
  if (stj == -1) return false;
  queue<pair<int, int> > q;
  q.push(pair<int, int>(sti, stj));
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    q.pop();
    for (int k = (0), ek = (4); k < ek; k++)
      if (B[i + dx[k]][j + dy[k]] == '#') {
        q.push(pair<int, int>(i + dx[k], j + dy[k]));
        B[i + dx[k]][j + dy[k]] = '.';
      }
  }
  for (int i = (1), ei = (n + 1); i < ei; i++)
    for (int j = (1), ej = (m + 1); j < ej; j++)
      if (B[i][j] == '#') return true;
  return false;
}
void run() {
  int n, m;
  cin >> n >> m;
  char A[52][52];
  memset(A, '.', sizeof(A));
  for (int i = (1), ei = (n + 1); i < ei; i++) scanf(" %s", A[i] + 1);
  int res = 2;
  int cnt = 0;
  for (int i = (1), ei = (n + 1); i < ei; i++)
    for (int j = (1), ej = (m + 1); j < ej; j++)
      if (A[i][j] == '#') ++cnt;
  if (cnt <= 2) {
    printf("-1\n");
    return;
  }
  for (int i = (1), ei = (n + 1); i < ei; i++)
    for (int j = (1), ej = (m + 1); j < ej; j++)
      if (A[i][j] == '#') {
        if (check(A, n, m, i, j)) {
          res = 1;
          break;
        }
      }
  printf("%d\n", res);
}
int main() {
  run();
  return 0;
}
