#include <bits/stdc++.h>
using namespace std;
const int maxn = 50 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
int n, m, px, py;
char mp[maxn][maxn];
bool vis[maxn][maxn];
bool is[maxn][maxn];
bool ok(int x, int y) {
  if (x >= 1 && x <= n && y >= 1 && y <= m) return true;
  return false;
}
void dfs(int x, int y) {
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int nx = dx[i] + x;
    int ny = dy[i] + y;
    if (ok(nx, ny) && is[nx][ny] && (!vis[nx][ny]) && (nx != px || ny != py)) {
      dfs(nx, ny);
    }
  }
}
bool solve() {
  memset(vis, false, sizeof(vis));
  bool flag = false;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (is[i][j] && (i != px || j != py)) {
        dfs(i, j);
        flag = true;
        break;
      }
    }
    if (flag) break;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (is[i][j] && (i != px || j != py) && (!vis[i][j])) return true;
    }
  }
  return false;
}
int main() {
  int cnt = 0;
  bool flag = false;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", mp[i] + 1);
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '#') is[i][j] = 1, cnt++;
    }
  }
  if (cnt == 1 || cnt == 2) {
    puts("-1");
    return 0;
  }
  px = py = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (is[i][j]) {
        px = i;
        py = j;
        if (solve()) {
          flag = true;
          break;
        }
      }
    }
    if (flag) break;
  }
  if (flag)
    puts("1");
  else
    puts("2");
}
