#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const int Mod = 1e9 + 7;
const int N = 55;
const int M = 55 * 55;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
inline long long dpow(long long a, long long b) {
  long long r = 1, t = a;
  while (b) {
    if (b & 1) r = (r * t) % Mod;
    b >>= 1;
    t = (t * t) % Mod;
  }
  return r;
}
inline long long fpow(long long a, long long b) {
  long long r = 1, t = a;
  while (b) {
    if (b & 1) r = (r * t);
    b >>= 1;
    t = (t * t);
  }
  return r;
}
vector<int> G[M];
char str[N][N];
int num[N][N], idx;
void Add(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}
int dfn[M], low[M], cnt;
void Tarjan(int x, int fa) {
  dfn[x] = low[x] = ++cnt;
  int son = 0;
  for (auto v : G[x]) {
    if (!dfn[v]) {
      Tarjan(v, x);
      low[x] = min(low[x], low[v]);
      if (x != fa && low[v] >= dfn[x]) puts("1"), exit(0);
      if (x == fa) son++;
    }
    low[x] = min(low[x], dfn[v]);
  }
  if (x == fa && son >= 2) puts("1"), exit(0);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%s", str[i] + 1);
    for (int j = 1; j <= m; j++)
      if (str[i][j] == '#') num[i][j] = ++idx;
  }
  if (idx < 3) puts("-1"), exit(0);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '.') continue;
      if (i < n && str[i + 1][j] == '#') Add(num[i][j], num[i + 1][j]);
      if (j < m && str[i][j + 1] == '#') Add(num[i][j], num[i][j + 1]);
    }
  }
  for (int i = 1; i <= idx; i++)
    if (!dfn[i]) Tarjan(i, i);
  puts("2");
  return 0;
}
