#include <bits/stdc++.h>
using namespace std;
int n, m, a[55][55], used[55][55], ans = 1000000007ll, c;
char tmp;
int dfs(int y, int x) {
  used[y][x] = 1;
  int ret = 1;
  if (a[y + 1][x] && !used[y + 1][x]) ret += dfs(y + 1, x);
  if (a[y - 1][x] && !used[y - 1][x]) ret += dfs(y - 1, x);
  if (a[y][x + 1] && !used[y][x + 1]) ret += dfs(y, x + 1);
  if (a[y][x - 1] && !used[y][x - 1]) ret += dfs(y, x - 1);
  return ret;
}
bool check(int y, int x) {
  bool ret = 0;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++) used[i][j] = 0;
  used[y][x] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] && !used[i][j]) {
        ret = (dfs(i, j) == c - 1);
        i = n + 10;
        break;
      }
  return ret;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> tmp;
      if (tmp == '#') a[i][j] = 1;
      c += a[i][j];
    }
  if (c <= 2) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j]) {
        int now = a[i + 1][j] + a[i - 1][j] + a[i][j + 1] + a[i][j - 1];
        ans = min(ans, now);
      }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] && !check(i, j)) {
        ans = 1;
        break;
      }
  cout << ans << endl;
  return 0;
}
