#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30) - 1;
const long long LINF = (1ll << 62) - 1;
const int DIRX[] = {-1, 0, 0, 1, -1, -1, 1, 1},
          DIRY[] = {0, -1, 1, 0, -1, 1, -1, 1};
const double ERR = 1e-11, PI = (2 * acos(0.0));
template <class T>
inline T MIN(T a, T b) {
  return ((a < b) ? (a) : (b));
}
template <class T>
inline T MAX(T a, T b) {
  return ((b < a) ? (a) : (b));
}
template <class T>
inline T ABS(T a) {
  return ((a < 0) ? (-a) : (a));
}
template <class T>
inline void checkMIN(T& a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkMAX(T& a, T b) {
  if (a < b) a = b;
}
template <class T>
inline T SQR(T x) {
  return (x * x);
}
template <class T>
T GCD(T a, T b) {
  return ((!b) ? (a) : GCD(b, a % b));
}
template <class T>
T fastPow(T Base, T Power) {
  T Result = 1;
  while (Power > 0) {
    if (Power & ((T)1)) Result *= Base;
    Power >>= 1;
    Base *= Base;
  }
  return Result;
}
template <class T>
T fastModPow(T Base, T Power, T Mod) {
  T Result = 1;
  while (Power > 0) {
    if (Power & ((T)1)) Result = (Result * Base) % Mod;
    Power >>= 1;
    Base = (Base * Base) % Mod;
  }
  return (Result % Mod);
}
inline int compDouble(double x, double y) {
  double d = x - y;
  if (d - ERR > 0.0)
    return 1;
  else if (d + ERR < 0.0)
    return -1;
  else
    return 0;
}
int n, m;
char a[53][53];
bool b[53][53];
int cc;
void dfs(int x, int y) {
  if (b[x][y]) return;
  b[x][y] = true;
  cc++;
  int k, i, j;
  for (k = 0; k < (4); k++) {
    i = x + DIRX[k];
    j = y + DIRY[k];
    if (1 <= i && i <= n && 1 <= j && j <= m && a[i][j] == '#' && !b[i][j]) {
      dfs(i, j);
    }
  }
}
int main() {
  int _kase = 1;
  int i, j, k, ans, x, y, xx, yy, l;
  while (_kase--) {
    scanf(" %d %d", &n, &m);
    int c = 0;
    for (i = (1); i <= (n); i++)
      for (j = (1); j <= (m); j++) {
        scanf(" %c", &a[i][j]);
        if (a[i][j] == '#') c++;
      }
    if (c <= 2) {
      ans = -1;
      cout << ans << endl;
    } else {
      for (i = (1); i <= (n); i++)
        for (j = (1); j <= (m); j++)
          if (a[i][j] == '#') {
            cc = 0;
            memset((b), (false), sizeof(b));
            dfs(i, j);
            if (cc != c) {
              ans = 0;
              goto hell;
            } else {
              goto step;
            }
          }
    step:;
      for (i = (1); i <= (n); i++)
        for (j = (1); j <= (m); j++)
          if (a[i][j] == '#') {
            for (k = 0; k < (4); k++) {
              x = i + DIRX[k];
              y = j + DIRY[k];
              if (1 <= x && x <= n && 1 <= y && y <= m && a[x][y] == '#') {
                a[x][y] = '.';
                cc = 0;
                memset((b), (false), sizeof(b));
                dfs(i, j);
                if (cc != c - 1) {
                  ans = 1;
                  goto hell;
                }
                a[x][y] = '#';
              }
            }
          }
      ans = 2;
    hell:
      cout << ans << endl;
    }
  }
  return 0;
}
