#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[2505];
vector<long long> tin, low;
vector<bool> visited;
vector<long long> articuation;
long long timer = 0;
void dfs(long long u, long long p) {
  visited[u] = true;
  tin[u] = low[u] = timer++;
  long long child = 0;
  for (auto v : adj[u]) {
    if (v == p) continue;
    if (visited[v]) {
      low[u] = min(low[u], tin[v]);
    } else {
      dfs(v, u);
      low[u] = min(low[u], low[v]);
      if (low[v] >= tin[u] && p != -1) {
        articuation.push_back(u);
      }
      ++child;
    }
  }
  if (p == -1 && child > 1) {
    articuation.push_back(u);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  char arr[n][m];
  tin = vector<long long>(n * m, 0);
  visited = vector<bool>(n * m, false);
  low = vector<long long>(n * m, 0);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> arr[i][j];
    }
  }
  long long y = 0, start = 0;
  bool flag = true;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (arr[i][j] == '#') {
        long long u = i * m + j;
        if (i != n - 1) {
          if (arr[i + 1][j] == '#') {
            adj[u].push_back((i + 1) * m + j);
          }
        }
        if (j != m - 1) {
          if (arr[i][j + 1] == '#') {
            adj[u].push_back((i)*m + j + 1);
          }
        }
        if (i != 0) {
          if (arr[i - 1][j] == '#') {
            adj[u].push_back((i - 1) * m + j);
          }
        }
        if (j != 0) {
          if (arr[i][j - 1] == '#') {
            adj[u].push_back((i)*m + j - 1);
          }
        }
        y++;
        if (flag) {
          start = u;
          flag = false;
        }
      }
    }
  }
  dfs(start, -1);
  if (y <= 2) {
    cout << -1 << endl;
  } else if (articuation.size() >= 1) {
    cout << 1 << endl;
  } else {
    cout << 2 << endl;
  }
  return 0;
}
