#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long INFL = LLONG_MAX;
const long double pi = acos(-1);
int N, M;
char T[55][55];
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
int was[55][55];
int dfs(int x, int y) {
  if (was[x][y]) return 0;
  was[x][y] = 1;
  int tot = 1;
  for (int(i) = 0, j123 = 4; (i) < j123; (i)++) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    if (xx < 1 || N < xx) continue;
    if (yy < 1 || M < yy) continue;
    if (T[xx][yy] == '.') continue;
    tot += dfs(xx, yy);
  }
  return tot;
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.precision(15);
  cout << fixed;
  cout.tie(0);
  for (int(i) = 0, j123 = 55; (i) < j123; (i)++)
    for (int(j) = 0, j123 = 55; (j) < j123; (j)++) T[i][j] = '.';
  cin >> N >> M;
  int tot = 0;
  for (int(i) = 1, j123 = N; (i) <= j123; (i)++)
    for (int(j) = 1, j123 = M; (j) <= j123; (j)++) cin >> T[i][j];
  for (int(i) = 1, j123 = N; (i) <= j123; (i)++)
    for (int(j) = 1, j123 = M; (j) <= j123; (j)++)
      if (T[i][j] == '#') tot++;
  if (tot <= 2) {
    cout << -1 << '\n';
    return 0;
  }
  int ans = INF;
  for (int(x) = 1, j123 = N; (x) <= j123; (x)++)
    for (int(y) = 1, j123 = M; (y) <= j123; (y)++) {
      if (T[x][y] == '.') continue;
      int cnt = 0;
      for (int(ii) = 0, j123 = 4; (ii) < j123; (ii)++) {
        int xx = x + dx[ii];
        int yy = y + dy[ii];
        if (T[xx][yy] == '#') cnt++;
      }
      ans = min(ans, cnt);
      T[x][y] = '.';
      int done = 0;
      for (int(xx) = 1, j123 = N; (xx) <= j123; (xx)++)
        if (!done)
          for (int(yy) = 1, j123 = M; (yy) <= j123; (yy)++) {
            if (T[xx][yy] == '.') continue;
            memset(was, 0, sizeof(was));
            ;
            int found = dfs(xx, yy);
            if (found + 1 < tot) {
              cout << 1 << '\n';
              return 0;
            }
            done = 1;
            break;
          }
      T[x][y] = '#';
    }
  cout << ans << '\n';
}
