#include <bits/stdc++.h>
using namespace std;
template <class T>
inline vector<pair<T, int> > FACTORISE(T n) {
  vector<pair<T, int> > R;
  for (T i = 2; n > 1;) {
    if (n % i == 0) {
      int C = 0;
      for (; n % i == 0; C++, n /= i)
        ;
      R.push_back(make_pair(i, C));
    }
    i++;
    if (i > n / i) i = n;
  }
  if (n > 1) R.push_back(make_pair(n, 1));
  return R;
}
template <class T>
inline T TOTIENT(T n) {
  vector<pair<T, int> > R = FACTORISE(n);
  T r = n;
  for (int i = 0; i < R.size(); i++) r = r / R[i].first * (R[i].first - 1);
  return r;
}
struct state {
  int row, col, val;
  state(int _r, int _c, int _v) : row(_r), col(_c), val(_v) {}
  bool operator<(const state &s) const { return val > s.val; }
};
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
char G[100][100];
int vis[100][100];
int n, m;
int dfs(int i, int j) {
  if (vis[i][j] == 1 || G[i][j] != '#') return 0;
  vis[i][j] = 1;
  for (int k = 0; k < 4; k++) {
    if (!vis[i + dx[k]][j + dy[k]]) dfs(i + dx[k], j + dy[k]);
  }
  return 1;
}
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  int cc = 0;
  for (int i = 0; i < n; i++) {
    scanf("%s", G[i]);
    for (int j = 0; j < m; j++) {
      if (G[i][j] == '#') cc++;
    }
  }
  if (cc == 1 || cc == 2) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (G[i][j] == '.') continue;
      G[i][j] = '.';
      int comp = 0;
      memset(vis, 0, sizeof(vis));
      for (int k = 0; k < 4; k++) {
        comp += dfs(i + dx[k], j + dy[k]);
      }
      if (comp > 1) {
        printf("1\n");
        return 0;
      }
      G[i][j] = '#';
    }
  }
  printf("2\n");
  return 0;
}
