#include <bits/stdc++.h>
using namespace std;
struct Position {
  int x, y;
} pos[10000];
int num_pos;
int n, m;
bool ok;
char matrix[60][60];
bool vis[60][60];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
void dfs(int x, int y) {
  vis[x][y] = true;
  int zx, zy;
  for (int i = 0; i < 4; i++) {
    zx = x + dx[i];
    zy = y + dy[i];
    if (!vis[zx][zy] && matrix[zx][zy] == '#') dfs(zx, zy);
  }
}
bool is_ok() {
  int x = 1, y = 1;
  for (int i = 1; i <= num_pos; i++) {
    x = pos[i].x;
    y = pos[i].y;
    vis[x][y] = false;
  }
  for (int i = 1; i <= num_pos; i++) {
    x = pos[i].x;
    y = pos[i].y;
    if (matrix[x][y] == '#') break;
  }
  dfs(x, y);
  for (int i = 1; i <= num_pos; i++) {
    x = pos[i].x;
    y = pos[i].y;
    if (!vis[x][y] && matrix[x][y] == '#') return true;
  }
  return false;
}
int main() {
  cin >> n >> m;
  num_pos = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf(" %c", &matrix[i][j]);
      if (matrix[i][j] == '#') {
        int t = ++num_pos;
        pos[t].x = i;
        pos[t].y = j;
      }
    }
  }
  if (num_pos <= 2) {
    cout << -1 << endl;
    exit(0);
  }
  ok = false;
  int x, y;
  for (int i = 1; i <= num_pos; i++) {
    if (ok) break;
    x = pos[i].x;
    y = pos[i].y;
    matrix[x][y] = '.';
    ok = is_ok();
    matrix[x][y] = '#';
  }
  if (ok)
    cout << 1 << endl;
  else
    cout << 2 << endl;
}
