#include <bits/stdc++.h>
using namespace std;
long long dr[] = {-1, 0, 0, 1};
long long dc[] = {0, -1, 1, 0};
char str[51][51];
long long R, C;
long long valid(long long r, long long c) {
  if (r >= 0 && c >= 0 && r < R && c < C)
    return (str[r][c] == '#');
  else
    return 0;
}
long long c2 = 0;
long long visit[51][51] = {0};
void dfs(long long i, long long j) {
  visit[i][j] = 1;
  c2++;
  for (long long k = 0; k <= 3; k++) {
    if (valid(i + dr[k], j + dc[k]) && visit[i + dr[k]][j + dc[k]] == 0) {
      dfs(i + dr[k], j + dc[k]);
    }
  }
}
long long visit2[51][51] = {0};
long long d[51][51] = {0};
long long low[51][51] = {0};
long long t = 0;
vector<long long> point;
void dfs2(long long i, long long j, long long p1 = -1, long long p2 = -1) {
  visit2[i][j] = 1;
  d[i][j] = low[i][j] = t++;
  long long child = 0;
  for (long long k = 0; k <= 3; k++) {
    if (valid(i + dr[k], j + dc[k])) {
      {
        if (i + dr[k] == p1 && j + dc[k] == p2)
          continue;
        else if (visit2[i + dr[k]][j + dc[k]])
          low[i][j] = min(low[i][j], d[i + dr[k]][j + dc[k]]);
        else {
          dfs2(i + dr[k], j + dc[k], i, j);
          low[i][j] = min(low[i][j], low[i + dr[k]][j + dc[k]]);
          if (low[i + dr[k]][j + dc[k]] >= d[i][j] && p1 != -1 && p2 != -1)
            point.push_back(i);
          child++;
        }
      }
    }
  }
  if (p1 == -1 && p2 != -1 && child > 1) point.push_back(i);
}
int main() {
  long long n, m, i, j, ans = 8000, cnt = 0, p, q;
  cin >> n >> m;
  R = n;
  C = m;
  long long deg[51][51] = {0};
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> str[i][j];
      if (str[i][j] == '#') {
        cnt++;
        p = i;
        q = j;
      }
    }
  }
  if (cnt == 0) {
    cout << -1 << endl;
    exit(0);
  }
  dfs(p, q);
  if (c2 == cnt) {
    dfs2(p, q);
    if (point.size() > 0) {
      cout << 1 << endl;
      exit(0);
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (str[i][j] == '#') {
          for (long long k = 0; k <= 3; k++) {
            if (valid(i + dr[k], j + dc[k])) {
              deg[i][j]++;
            }
          }
          ans = min(ans, deg[i][j]);
        }
      }
    }
    if (ans == 0 || cnt == 2)
      cout << -1 << endl;
    else
      cout << ans << endl;
  } else
    cout << -1 << endl;
}
