#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
char grid[55][55];
vector<int> g[55 * 55];
int low[55 * 55], dfn[55 * 55], dfs_idx;
int n, m;
bool find_cut;
inline int node_idx(int x, int y) { return (x - 1) * m + y; }
void dfs(int u, int fa) {
  dfn[u] = low[u] = ++dfs_idx;
  int ch = 0;
  for (int& v : g[u]) {
    if (!dfn[v]) {
      dfs(v, u);
      ch++;
      low[u] = min(low[u], low[v]);
      if (dfn[u] <= low[v] && fa != -1) find_cut = true;
    } else if (v != fa) {
      low[u] = min(low[u], dfn[v]);
    }
  }
  if (ch > 1 && fa == -1) find_cut = true;
}
int main() {
  scanf("%d%d", &n, &m);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s", grid[i] + 1);
    for (int j = 1; j <= m; j++)
      if (grid[i][j] == '#') cnt++;
  }
  if (cnt <= 2) {
    puts("-1");
    exit(0);
  }
  int stx, sty;
  for (int x = 1; x <= n; x++) {
    for (int y = 1; y <= m; y++) {
      if (grid[x][y] != '#') continue;
      stx = x, sty = y;
      for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if (1 <= nx && nx <= n && 1 <= ny && ny <= m && grid[nx][ny] == '#') {
          g[node_idx(nx, ny)].push_back(node_idx(x, y));
          g[node_idx(x, y)].push_back(node_idx(nx, ny));
        }
      }
    }
  }
  dfs(node_idx(stx, sty), -1);
  printf("%d\n", find_cut ? 1 : 2);
  return 0;
}
