#include <bits/stdc++.h>
using std::min;
const int kFx[4] = {-1, 1, 0, 0};
const int kFy[4] = {0, 0, -1, 1};
const int kMaxN = 50, kMaxM = 50;
int n, m;
char g[kMaxN][kMaxM + 1];
int bcnt;
bool vis[kMaxN][kMaxM];
int deg[kMaxN][kMaxN];
int tot;
int dcnt, dfn[kMaxN * kMaxM], low[kMaxN * kMaxM];
bool gd;
int root, cnt;
void Dfs(int x, int y) {
  vis[x][y] = true;
  ++tot;
  for (int d = 0; d < 4; ++d) {
    int nx = x + kFx[d];
    int ny = y + kFy[d];
    if (nx >= 0 && nx < n && ny >= 0 && ny < m && g[nx][ny] == '#') {
      ++deg[x][y];
      if (!vis[nx][ny]) Dfs(nx, ny);
    }
  }
}
void Tar(int u, int p) {
  low[u] = dfn[u] = ++dcnt;
  int ux = u / m, uy = u % m;
  for (int d = 0; d < 4; ++d) {
    int vx = ux + kFx[d], vy = uy + kFy[d];
    if (vx >= 0 && vx < n && vy >= 0 && vy < m && g[vx][vy] == '#') {
      int v = vx * m + vy;
      if (v == p) continue;
      if (!dfn[v]) {
        Tar(v, u);
        low[u] = min(low[u], low[v]);
        if (u != root && dfn[u] <= low[v]) gd = true;
        if (u == root) {
          ++cnt;
          if (cnt > 1) gd = true;
        }
      } else
        low[u] = min(low[u], dfn[v]);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", g[i]);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (g[i][j] == '#' && !vis[i][j]) {
        ++bcnt;
        Dfs(i, j);
      }
  if (bcnt > 1)
    printf("0\n");
  else {
    if (tot <= 2)
      printf("-1\n");
    else {
      bool go = false;
      for (int i = 0; i < n && !go; ++i)
        for (int j = 0; j < m && !go; ++j)
          if (g[i][j] == '#') {
            root = i * m + j;
            Tar(i * m + j, -1);
            go = true;
          }
      if (gd)
        printf("1\n");
      else
        printf("2\n");
    }
  }
  return 0;
}
