#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <class T>
inline T bigmod(T p, T e, T M) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    long long int t = bigmod(p, e / 2, M);
    return (T)((t * t) % M);
  }
  return (T)((long long int)bigmod(p, e - 1, M) * (long long int)p) % M;
}
template <class T>
inline T bigexp(T p, T e) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    long long int t = bigexp(p, e / 2);
    return (T)((t * t));
  }
  return (T)((long long int)bigexp(p, e - 1) * (long long int)p);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
int dx4[] = {1, 0, -1, 0};
int dy4[] = {0, 1, 0, -1};
int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char s[55][55];
int mn, mx, n, m, a, b, c, d, t = 0;
bool bl[51][51];
int dfs(int i, int j) {
  if (i < 0 || i > n || j < 0 || j > m) return 0;
  if (s[i][j] == '.' || bl[i][j] == true) return 0;
  int ret = 0, x, y;
  bl[i][j] = true;
  for (__typeof(3) k = (0); k <= (3); k++) {
    x = i + dx4[k];
    y = j + dy4[k];
    ret += dfs(x, y);
  }
  return ret + 1;
}
int main() {
  scanf("%d %d", &n, &m);
  n--;
  for (__typeof(n) i = (0); i <= (n); i++) scanf("%s", &s[i]);
  mn = 2000000000;
  mx = 0;
  m--;
  for (__typeof(n) i = (0); i <= (n); i++) {
    for (__typeof(m) j = (0); j <= (m); j++) {
      if (s[i][j] == '#') {
        a = 0, b = 0, c = 0, d = 0;
        if (i - 1 >= 0)
          if (s[i - 1][j] == '#') a = 1;
        if (i + 1 <= n)
          if (s[i + 1][j] == '#') b = 1;
        if (j - 1 >= 0)
          if (s[i][j - 1] == '#') c = 1;
        if (j + 1 <= m)
          if (s[i][j + 1] == '#') d = 1;
        a = a + b + c + d;
        mn = min(mn, a);
        mx = max(mx, a);
        t++;
      }
    }
  }
  if (mx <= 1 && t <= 2) {
    printf("-1");
  } else {
    int r;
    for (__typeof(n) i = (0); i <= (n); i++)
      for (__typeof(m) j = (0); j <= (m); j++)
        if (s[i][j] == '#') {
          s[i][j] = '.';
          a = 0, b = 0, c = 0, d = 0;
          if (i - 1 >= 0)
            if (s[i - 1][j] == '#') a = 1;
          if (i + 1 <= n)
            if (s[i + 1][j] == '#') b = 1;
          if (j - 1 >= 0)
            if (s[i][j - 1] == '#') c = 1;
          if (j + 1 <= m)
            if (s[i][j + 1] == '#') d = 1;
          if (a > 0)
            r = dfs(i - 1, j);
          else if (b > 0)
            r = dfs(i + 1, j);
          else if (c > 0)
            r = dfs(i, j - 1);
          else if (d > 0)
            r = dfs(i, j + 1);
          memset(bl, false, sizeof bl);
          if (t - 1 > r) {
            mn = 1;
            break;
          }
          s[i][j] = '#';
        }
    printf("%d", mn);
  }
  return 0;
}
