#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1.0);
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 (b > a) a = b;
}
template <class T>
inline T gcd(T a, T b) {
  if (!b) return a;
  return gcd(b, a % b);
}
char a[100][100];
int n, m, i, j, jing = 0, fi[26], fj[26], top, flag[100][100], I, J;
int _in(int i, int j) {
  if (i >= 0 && i < n && j >= 0 && j < m) return 1;
  return 0;
}
bool dfs(int i, int j) {
  if (!_in(i, j) || a[i][j] != '#') return false;
  if (flag[i][j]) return false;
  flag[i][j] = 1;
  if (i == I && j == J) return true;
  if (dfs(i - 1, j) || dfs(i + 1, j) || dfs(i, j - 1) || dfs(i, j + 1))
    return true;
  return false;
}
int main() {
  scanf("%d%d ", &n, &m);
  for (i = 0; i < (n); ++i) gets(a[i]);
  for (i = 0; i < (n); ++i)
    for (j = 0; j < (m); ++j) {
      if (a[i][j] == '#') jing++;
    }
  if (jing == 0 || jing == 1 || jing == 2)
    printf("-1\n");
  else {
    int one = 0;
    for (i = 0; i < (n); ++i)
      for (j = 0; j < (m); ++j)
        if (a[i][j] == '#') {
          top = 0;
          if (_in(i - 1, j))
            if (a[i - 1][j] == '#') {
              ++top;
              fi[top] = i - 1;
              fj[top] = j;
            }
          if (_in(i + 1, j))
            if (a[i + 1][j] == '#') {
              ++top;
              fi[top] = i + 1;
              fj[top] = j;
            }
          if (_in(i, j - 1))
            if (a[i][j - 1] == '#') {
              ++top;
              fi[top] = i;
              fj[top] = j - 1;
            }
          if (_in(i, j + 1))
            if (a[i][j + 1] == '#') {
              ++top;
              fi[top] = i;
              fj[top] = j + 1;
            }
          if (top == 1) continue;
          a[i][j] = '.';
          int k;
          for (k = (2); k <= (top); ++k) {
            memset(flag, 0, sizeof flag);
            I = fi[k];
            J = fj[k];
            if (!dfs(fi[1], fj[1])) {
              one = 1;
              goto _;
            }
          }
          a[i][j] = '#';
        }
  _:;
    if (one)
      printf("1\n");
    else
      printf("2\n");
  }
}
