#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7, N = 1e6 + 5;
char a[51][51];
int n, m;
int vis[51][51];
void dfs(int i, int j) {
  vis[i][j] = 1;
  if (i - 1 >= 0 and a[i - 1][j] == '#' and vis[i - 1][j] == 0) dfs(i - 1, j);
  if (i + 1 < n and a[i + 1][j] == '#' and vis[i + 1][j] == 0) dfs(i + 1, j);
  if (j - 1 >= 0 and a[i][j - 1] == '#' and vis[i][j - 1] == 0) dfs(i, j - 1);
  if (j + 1 < m and a[i][j + 1] == '#' and vis[i][j + 1] == 0) dfs(i, j + 1);
}
int func() {
  for (int i = 0; i < 51; i++)
    for (int j = 0; j < 51; j++) vis[i][j] = 0;
  int check = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#') check = 1, dfs(i, j);
      if (check) break;
    }
    if (check) break;
  }
  check = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#' and vis[i][j] == 0) {
        check = 0;
        break;
      }
    }
  }
  return check;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  cin >> n >> m;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '#') cnt++;
    }
  }
  if (cnt <= 2) cout << -1, exit(0);
  int ans = 2;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#') {
        a[i][j] = '.';
        if (func() == 0) {
          ans = 1;
          break;
        }
        a[i][j] = '#';
      }
    }
    if (ans == 1) break;
  }
  cout << ans;
}
