#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;
vector<string> v;
int used[50][50] = {0};
int n, m;
int vis = 0;
void dfs(int i, int j) {
  used[i][j] = 1;
  vis++;
  for (int x = -1; x <= 1; x++)
    for (int y = -1; y <= 1; y++) {
      if (abs(x + y) != 1) continue;
      int nx = i + x, ny = j + y;
      if (nx >= 0 && nx < n && ny >= 0 && ny < m && v[nx][ny] == '#' &&
          !used[nx][ny]) {
        dfs(nx, ny);
      }
    }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  int mint = 100000000;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] == '#') cnt++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] != '#') continue;
      int temp = 0;
      for (int x = -1; x <= 1; x++)
        for (int y = -1; y <= 1; y++) {
          if (abs(x + y) != 1) continue;
          int nx = i + x, ny = j + y;
          if (nx >= 0 && nx < n && ny >= 0 && ny < m && v[nx][ny] == '#') {
            temp++;
          }
        }
      if (cnt - temp > 1) {
        mint = min(mint, temp);
      }
    }
  }
  for (int i1 = 0; i1 < n; i1++) {
    for (int j1 = 0; j1 < m; j1++) {
      if (v[i1][j1] != '#') continue;
      v[i1][j1] = '.';
      vis = 0;
      for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) used[i][j] = 0;
      bool df = true;
      bool div = false;
      for (int i = 0; i < n && df; i++)
        for (int j = 0; j < m && df; j++)
          if (v[i][j] == '#') {
            dfs(i, j);
            if (vis + 1 != cnt) div = true;
            df = false;
          }
      if (div) mint = min(mint, 1);
      v[i1][j1] = '#';
    }
  }
  if (mint == 100000000) {
    printf("-1");
  } else {
    printf("%d", mint);
  }
}
