#include <bits/stdc++.h>
using namespace std;
int dx[5] = {
    0,
    1,
    0,
    -1,
};
int dy[5] = {
    1,
    0,
    -1,
    0,
};
int n, m;
char a[55][55];
bool chk[55][55];
bool discon(int v1, int v2) {
  a[v1][v2] = '.';
  queue<pair<int, int> > q;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) chk[i][j] = false;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == '#') {
        q.push(make_pair(i, j));
        chk[i][j] = true;
        while (!q.empty()) {
          int x = q.front().first;
          int y = q.front().second;
          q.pop();
          for (int k = 0; k < 4; k++) {
            int nx = x + dx[k], ny = y + dy[k];
            if (!chk[nx][ny] && a[nx][ny] == '#') {
              q.push(make_pair(nx, ny));
              chk[nx][ny] = true;
            }
          }
        }
        i = n + 3;
        break;
      }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (!chk[i][j] && a[i][j] == '#') {
        a[v1][v2] = '#';
        return true;
      }
  a[v1][v2] = '#';
  return false;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", &a[i][1]);
  int op = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == '#') op++;
  if (op <= 2) {
    printf("-1");
    return 0;
  }
  int mi = 2;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == '#')
        if (discon(i, j)) mi = min(mi, 1);
  printf("%d", mi);
  return 0;
}
