#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T b, T p, T M) {
  T ret = 1;
  for (; p > 0; p >>= 1) {
    if (p & 1) ret = (ret * b) % M;
    b = (b * b) % M;
  }
  return (T)ret;
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, 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 lcm(T a, T b) {
  return a * b / gcd<T>(a, b);
}
template <class T>
inline T power(T b, T p) {
  unsigned long long int x = 1;
  while (p--) x *= b;
  return x;
}
const int mod = 1000000007;
int n, m, cnt, nowCnt;
int vis[52][52];
char grid[55][55];
int dx[] = {+1, -1, +0, +0};
int dy[] = {+0, +0, +1, -1};
bool isValid(int x, int y) {
  if (x < 1 || x > n) return false;
  if (y < 1 || y > m) return false;
  if (grid[x][y] != '#' || vis[x][y] == 1) return false;
  return true;
}
void dfs(int x, int y) {
  vis[x][y] = 1;
  nowCnt++;
  for (int i = 0; i < 4; i++) {
    int tmpX = x + dx[i];
    int tmpY = y + dy[i];
    if (isValid(tmpX, tmpY)) dfs(tmpX, tmpY);
  }
}
bool canRemove(int x, int y) {
  if (grid[x][y] != '#') return false;
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      vis[i][j] = 0;
    }
  }
  vis[x][y] = 1;
  nowCnt = 1;
  if (isValid(x + 1, y))
    dfs(x + 1, y);
  else if (isValid(x - 1, y))
    dfs(x - 1, y);
  else if (isValid(x, y + 1))
    dfs(x, y + 1);
  else if (isValid(x, y - 1))
    dfs(x, y - 1);
  if (nowCnt == cnt) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> grid[i][j];
      cnt += grid[i][j] == '#';
    }
  }
  if (cnt < 3) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (canRemove(i, j)) {
        cout << 1 << endl;
        return 0;
      }
    }
  }
  cout << 2 << endl;
  return 0;
}
