#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    T t = bigmod(p, e / 2, M);
    return (t * t) % M;
  }
  return (bigmod(p, e - 1, M) * p) % M;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T multimod(T a, T b, T m) {
  T ans = 0ll;
  a %= m, b %= m;
  while (b) {
    if (b & 1ll) ans = m - ans > a ? (ans + a) : (ans + a - m);
    b >>= 1ll;
    a = (m - a) > a ? a + a : a + a - m;
  }
  return (T)ans;
}
void sc(int &a) { scanf("%d", &a); }
void sc(long long &a) { scanf("%lld", &a); }
void sc(double &a) { scanf("%lf", &a); }
void sc(int &a, int &b) { scanf("%d %d", &a, &b); }
void sc(long long &a, long long &b) { scanf("%lld %lld", &a, &b); }
void sc(int &a, int &b, int &c) { scanf("%d %d %d", &a, &b, &c); }
void sc(int &a, int &b, long long &c) { scanf("%d %d %lld", &a, &b, &c); }
void sc(long long &a, long long &b, long long &c) {
  scanf("%lld %lld %lld", &a, &b, &c);
}
void sc(string &str) { cin >> str; }
void sc(char *(str)) { scanf(" %s", str); }
void sc(char &c) { scanf(" %c", &c); }
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
char str[100][100];
bool vis[55][55];
int n, m;
void DFS(int x, int y) {
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int adx = x + dr[i];
    int ady = y + dc[i];
    if (adx < 0 || adx >= n || ady < 0 || ady >= m || vis[adx][ady] ||
        str[adx][ady] == '.')
      continue;
    DFS(adx, ady);
  }
  return;
}
int main() {
  int i, j, k, cases = 1;
  int id = 0;
  int t;
  int u, v, w;
  int a, b, p, q, c, l;
  sc(n, m);
  for (i = 0; i < n; i++) sc(str[i]);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (str[i][j] == '#') {
        str[i][j] = '.';
        int cnt = 0;
        memset(vis, false, sizeof vis);
        for (p = 0; p < n; p++) {
          for (q = 0; q < m; q++) {
            if (!vis[p][q] && str[p][q] == '#') {
              DFS(p, q);
              cnt++;
            }
          }
        }
        if (cnt > 1) {
          printf("1\n");
          return 0;
        }
        str[i][j] = '#';
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (str[i][j] == '.') continue;
      for (k = 0; k < n; k++) {
        for (l = 0; l < m; l++) {
          if (k == i && l == j) continue;
          if (str[k][l] == '.') continue;
          str[i][j] = str[k][l] = '.';
          int cnt = 0;
          memset(vis, false, sizeof vis);
          for (p = 0; p < n; p++) {
            for (q = 0; q < m; q++) {
              if (!vis[p][q] && str[p][q] == '#') {
                DFS(p, q);
                cnt++;
              }
            }
          }
          if (cnt > 1) {
            printf("2\n");
            return 0;
          }
          str[i][j] = '#';
          str[k][l] = '#';
        }
      }
    }
  }
  printf("-1\n");
  return 0;
}
