#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int P = 1e9 + 7;
const int N = 2e7;
struct node {
  int x;
  int y;
} s, p;
int vis[55][55];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
long long n, m, ans, temp;
queue<node> q;
char a[55][55];
void dfs(int x1, int y1) {
  vis[x1][y1] = 1;
  for (int i = 0; i < 4; i++) {
    int xx = x1 + dx[i];
    int yy = y1 + dy[i];
    if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && a[xx][yy] == '#' &&
        !vis[xx][yy]) {
      dfs(xx, yy);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  ans = 0;
  temp = 0;
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= m; ++j) {
      cin >> a[i][j];
      if (a[i][j] == '#') ans++;
    }
  }
  temp = 0;
  long long sum = 0;
  long long temp1 = 0;
  if (ans < 3)
    cout << "-1" << endl;
  else {
    for (long long i = 1; i <= n; ++i) {
      for (long long j = 1; j <= m; ++j) {
        if (a[i][j] == '#') {
          temp++;
          a[i][j] = '.';
          sum = 0;
          for (long long k = 1; k <= n; ++k) {
            for (long long l = 1; l <= m; ++l) {
              if (a[k][l] == '.') continue;
              if (!vis[k][l]) {
                sum++;
                dfs(k, l);
                if (sum > 1) temp1 = 1;
              }
            }
          }
          a[i][j] = '#';
          memset(vis, 0, sizeof(vis));
        }
      }
    }
    if (temp1 == 0 && temp > 2) temp1 = 2;
    cout << temp1 << endl;
  }
}
