#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, res;
bool vis[55][55];
char s[55][55];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool inb(int x, int y) { return x > 0 && x <= n && y > 0 && y <= m; }
void dfs(int x, int y) {
  vis[x][y] = true;
  for (int i = (0); i <= (3); i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (inb(nx, ny) && !vis[nx][ny]) dfs(nx, ny);
  }
  return;
}
bool ccp() {
  memset(vis, 0, sizeof(vis));
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (m); j++)
      if (s[i][j] == '.') vis[i][j] = 1;
  int c = 0;
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (m); j++) {
      if (!vis[i][j]) {
        if (c) return false;
        c++;
        dfs(i, j);
      }
    }
  return true;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (1); i <= (n); i++) {
    scanf(" %s", s[i] + 1);
    for (int j = (1); j <= (m); j++)
      if (s[i][j] == '#') cnt++;
  }
  if (cnt <= 2) {
    printf("-1\n");
    return 0;
  }
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (m); j++) {
      if (s[i][j] == '.') continue;
      s[i][j] = '.';
      if (!ccp()) {
        printf("1\n");
        return 0;
      }
      s[i][j] = '#';
    }
  printf("2\n");
  return 0;
}
