#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
template <class T>
inline T sqr(T a) {
  return a * a;
}
int n, m;
vector<string> g;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
bool ok(int x, int y) {
  return x >= 0 && y >= 0 && x < n && y < m && g[x][y] == '#';
}
int f(int x, int y) {
  int res = 0;
  for (int i = 0; i < 4; ++i) {
    int tx = x + dx[i];
    int ty = y + dy[i];
    if (ok(tx, ty)) ++res;
  }
  return res;
}
bool was[50][50] = {0};
void dfs(int x, int y) {
  was[x][y] = 1;
  for (int i = 0; i < 4; ++i) {
    int tx = x + dx[i], ty = y + dy[i];
    if (ok(tx, ty) && !was[tx][ty]) dfs(tx, ty);
  }
}
pair<int, int> getf() {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (!was[i][j] && ok(i, j)) return make_pair(i, j);
    }
  }
  return make_pair(-1, -1);
}
int main() {
  scanf("%d%d", &n, &m);
  g.resize(n);
  int r = 0;
  for (int i = 0; i < n; ++i) {
    cin >> g[i];
    for (int j = 0; j < m; ++j) {
      if (g[i][j] == '#') ++r;
    }
  }
  if (r <= 2) {
    cout << -1;
    return 0;
  }
  int res = 123456789;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (g[i][j] != '#') continue;
      memset(was, 0, sizeof was);
      int q = f(i, j);
      res = min(res, q);
      was[i][j] = 1;
      pair<int, int> t = getf();
      memset(was, 0, sizeof was);
      was[i][j] = 1;
      dfs(t.first, t.second);
      t = getf();
      if (t.first != -1) {
        cout << 1;
        return 0;
      }
    }
  }
  cout << res;
  return 0;
}
