#include <bits/stdc++.h>
char field[52][52];
bool visited[52][52];
int min = 100;
int n, m, i, j, cnt;
int checked;
void dfs(int x, int y) {
  if (visited[y][x]) return;
  visited[y][x] = true;
  checked++;
  if (field[y - 1][x] == '#') dfs(x, y - 1);
  if (field[y + 1][x] == '#') dfs(x, y + 1);
  if (field[y][x - 1] == '#') dfs(x - 1, y);
  if (field[y][x + 1] == '#') dfs(x + 1, y);
}
bool check() {
  int i, j;
  checked = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) visited[i][j] = false;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (field[i][j] == '#') {
        dfs(j, i);
        return checked == cnt - 1;
      }
}
int main() {
  scanf("%d %d\n", &n, &m);
  for (i = 1; i <= n; i++) scanf("%s\n", field[i] + 1);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (field[i][j] == '#') cnt++;
  if (cnt < 3) {
    printf("-1\n");
    return 0;
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (field[i][j] == '#') {
        field[i][j] = '.';
        if (!check()) {
          printf("1\n");
          return 0;
        }
        field[i][j] = '#';
      }
  printf("2\n");
  return 0;
}
