#include <bits/stdc++.h>
using namespace std;
long long get() {
  char c = getchar();
  long long x = 0LL;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    x *= 10LL;
    x += (c - '0');
    c = getchar();
  }
  return x;
}
int n, m, y, fx, fy, sx, sy;
char c;
bool f[50][50];
int num;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
bool used[50][50];
bool in(int x, int y) {
  return (x >= 0 && x < n && y >= 0 && y < m && f[x][y] && !used[x][y]);
}
void dfs(int x, int y) {
  num++;
  used[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int xx = x + dx[i], yy = y + dy[i];
    if (in(xx, yy)) dfs(xx, yy);
  }
}
int main() {
  fx = fy = sx = sy = -1;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> c;
      if (c == '#') {
        f[i][j] = true, y++;
        if (fx == -1)
          fx = i, fy = j;
        else if (sx == -1)
          sx = i, sy = j;
      }
    }
  if (y < 3) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      memset(used, 0, sizeof(used));
      num = 0;
      if (!f[i][j]) continue;
      f[i][j] = false;
      if (i == fx && j == fy)
        dfs(sx, sy);
      else
        dfs(fx, fy);
      if (num != y - 1) {
        cout << 1;
        return 0;
      }
      f[i][j] = true;
    }
  cout << 2;
  return 0;
}
