#include <bits/stdc++.h>
using namespace std;
int n, m;
char str[51][100];
int tot = 0;
char MAP[51][51];
bool vis[51][51];
int to[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1};
void dfs(int x, int y) {
  vis[x][y] = 1;
  for (int d = 0; d < 4; d++) {
    int nx, ny;
    nx = x + to[d][0];
    ny = y + to[d][1];
    if (nx < 0 || nx >= n || ny < 0 || ny >= m) {
      continue;
    }
    if (!vis[nx][ny] && MAP[nx][ny] == '#') {
      dfs(nx, ny);
    }
  }
}
bool isConnected() {
  memset(vis, false, sizeof(vis));
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!vis[i][j] && MAP[i][j] == '#') {
        dfs(i, j);
        cnt++;
      }
    }
  }
  return cnt <= 1;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    int ans = 2;
    tot = 0;
    for (int i = 0; i < n; i++) {
      scanf("%s", str[i]);
      for (int j = 0; j < m; j++) {
        if (str[i][j] == '#') {
          tot++;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        MAP[i][j] = str[i][j];
      }
    }
    if (!isConnected()) {
      puts("0");
      continue;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        MAP[i][j] = '.';
        if (!isConnected()) {
          puts("1");
          return 0;
        }
        MAP[i][j] = str[i][j];
      }
    }
    if (tot <= 3) {
      puts("-1");
      continue;
    }
    puts("2");
    continue;
  }
}
