#include <bits/stdc++.h>
using namespace std;
char board[55][55];
int seen[55][55], n, m, ax, ay;
int x[4], y[4];
void dfs(int u, int v) {
  if (0) cout << "BEG " << u << " " << v << endl;
  int i, tu, tv, cDeg = 0;
  for (i = 0; i < 4; i++) {
    tu = y[i] + u;
    tv = x[i] + v;
    if (tv == ax && tu == ay) continue;
    if (tu >= 0 && tv >= 0 && tu < n && tv < m && board[tu][tv] == '#') {
      if (seen[tu][tv]) continue;
      seen[tu][tv] = 1;
      dfs(tu, tv);
    }
  }
  if (0) cout << "DONE " << u << " " << v << " " << cDeg << endl;
}
int main() {
  int i, j, minDeg = 1000000, cnt = 0;
  cin >> n >> m;
  x[0] = 1;
  x[1] = -1;
  x[2] = 0;
  x[3] = 0;
  y[0] = 0;
  y[1] = 0;
  y[2] = 1;
  y[3] = -1;
  for (i = 0; i < n; i++) {
    cin >> board[i];
    board[i][m] = '\0';
  }
  bool found = false;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (board[i][j] == '#') {
        cnt++;
      }
    }
  }
  if (cnt < 3) {
    cout << -1 << endl;
    return 0;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (board[i][j] == '#') {
        memset(seen, 0, sizeof(seen));
        ay = i;
        ax = j;
        int tu, tv;
        for (int k = 0; k < 4; k++) {
          tu = y[k] + ay;
          tv = x[k] + ax;
          if (tu >= 0 && tv >= 0 && tu < n && tv < m && board[tu][tv] == '#') {
            dfs(tu, tv);
            seen[tu][tv] = 1;
            break;
          }
        }
        for (int k = 0; k < n; k++) {
          for (int p = 0; p < m; p++)
            if (board[k][p] == '#' && !(k == ay && p == ax) && !seen[k][p]) {
              cout << 1 << endl;
              return 0;
            }
        }
      }
    }
  }
  cout << 2 << endl;
  return 0;
}
