#include <bits/stdc++.h>
using namespace std;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class type>
type MODEXPO(type a, type b, int mod) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0)
    return MODEXPO((a * a) % mod, b / 2, mod);
  else
    return (a * MODEXPO((a * a) % mod, (b - 1) / 2, mod)) % mod;
}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
const long long M = 1e18;
const int N = 50 + 5;
const char dc[4] = {'D', 'R', 'U', 'L'};
int n, m, timer = 1, low[N][N], tin[N][N], ri, rj, cnt, co, vis[N][N];
char ch[N][N];
bool check(int x, int y) {
  return x >= 0 and x < n and y >= 0 and y < m and ch[x][y] == '#';
}
void dfs(int i, int j, int pi, int pj) {
  low[i][j] = tin[i][j] = timer++;
  vis[i][j] = 1;
  int cur = 0, ni, nj;
  for (int k = 0; k < 4; k++) {
    ni = i + dx[k], nj = j + dy[k];
    if (!check(ni, nj)) continue;
    if (ni == pi and nj == pj) continue;
    if (!vis[ni][nj]) {
      cur++;
      dfs(ni, nj, i, j);
      low[i][j] = min(low[i][j], low[ni][nj]);
      if ((i != ri or j != rj) and tin[i][j] <= low[ni][nj]) co = 1;
    } else
      low[i][j] = min(low[i][j], tin[ni][nj]);
  }
  if (cur >= 2 and i == ri and j == rj) co = 1;
  return;
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> ch[i][j];
      if (ch[i][j] == '#') {
        ri = i, rj = j;
        cnt++;
      }
    }
  if (cnt < 3) {
    cout << "-1";
    return;
  }
  co = 2;
  dfs(ri, rj, -1, -1);
  cout << co;
}
int main() {
  fast();
  solve();
  return 0;
}
