#include <bits/stdc++.h>
using namespace std;
long long int n, m;
string a[100];
char visited[100][100];
void chichi() {
  for (long long int i = 0; i < n; i++)
    for (long long int j = 0; j < m; j++) visited[i][j] = a[i][j];
}
void dfs(long long int x, long long int y) {
  visited[x][y] = '.';
  long long int dx[4] = {0, 1, 0, -1};
  long long int dy[4] = {1, 0, -1, 0};
  for (long long int i = 0; i < 4; i++) {
    long long int xx = x + dx[i];
    long long int yy = y + dy[i];
    if (xx >= 0 && xx < n && yy >= 0 && yy < m && visited[xx][yy] != '.') {
      dfs(xx, yy);
    }
  }
}
int main() {
  long long int t, i, j, x, y, c;
  cin >> n >> m;
  c = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    for (j = 0; j < m; j++)
      if (a[i][j] == '#') c++;
  }
  if (c <= 2) {
    printf("-1\n");
    return 0;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[i][j] == '#') {
        long long int dx[4] = {0, 1, 0, -1};
        long long int dy[4] = {1, 0, -1, 0};
        for (long long int ii = 0; ii < 4; ii++) {
          long long int xx = i + dx[ii];
          long long int yy = j + dy[ii];
          if (xx >= 0 && xx < n && yy >= 0 && yy < m && a[xx][yy] != '.') {
            chichi();
            visited[i][j] = '.';
            dfs(xx, yy);
            break;
          }
        }
        for (x = 0; x < n; x++)
          for (y = 0; y < m; y++)
            if (visited[x][y] == '#') {
              printf("1\n");
              return 0;
            }
      }
    }
  }
  printf("2\n");
  return 0;
}
