#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
const int M = 1e6;
const int oo = 1e9;
const int mod = 1e9 + 7;
int cnt, cnt2;
string g[50];
int n, m;
bool vis[51][51];
void dfs(int r, int c) {
  if (r == n || c == m || r < 0 || c < 0 || vis[r][c] || g[r][c] == '.') return;
  vis[r][c] = 1;
  cnt++;
  dfs(r + 1, c);
  dfs(r - 1, c);
  dfs(r, c + 1);
  dfs(r, c - 1);
}
int main() {
  cin >> n >> m;
  pair<int, int> p = {-1, -1}, p2;
  for (int i = 0; i < n; i++) {
    cin >> g[i];
    for (int j = 0; j < m; j++) {
      cnt2 += g[i][j] == '#';
      if (g[i][j] == '#') {
        if (p.first == -1)
          p = {i, j};
        else
          p2 = {i, j};
      }
    }
  }
  if (cnt2 <= 2) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '.') continue;
      memset(vis, 0, sizeof(vis));
      cnt = 0;
      g[i][j] = '.';
      if (i == p.first && j == p.second)
        dfs(p2.first, p2.second);
      else
        dfs(p.first, p.second);
      g[i][j] = '#';
      if (cnt != cnt2 - 1) {
        puts("1");
        return 0;
      }
    }
  puts("2");
}
