#include <bits/stdc++.h>
using namespace std;
int n, m, dp[55][55], res = 3000, num;
int p1[] = {1, -1, 0, 0}, p2[] = {0, 0, 1, -1}, ex;
vector<pair<int, int> > vec;
char in[60][60];
bool vis[50][50];
int DFS(int x, int y, int parx, int pary) {
  if (vis[x][y]) return 0;
  int ret = 1;
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int X = x + p1[i], Y = y + p2[i];
    if (X < 0 || X >= n || Y < 0 || Y >= m || in[X][Y] != '#' ||
        (X == parx && Y == pary))
      continue;
    ret += DFS(X, Y, x, y);
  }
  return ret;
}
bool Solve(int a, int b, int f) {
  memset(vis, 0, sizeof vis);
  int x = DFS(a, b, -1, -1);
  if (x == ex - f) return 1;
  return 0;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", in[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (in[i][j] == '#') ex++, vec.push_back(make_pair(i, j));
  for (int i = 0; i < vec.size(); i++) {
    int x = vec[i].first, y = vec[i].second, gox = -1, goy = -1;
    if (i > 0)
      gox = vec[i - 1].first, goy = vec[i - 1].second;
    else if (i < vec.size() - 1)
      gox = vec[i + 1].first, goy = vec[i + 1].second;
    if (gox == -1 && goy == -1) continue;
    in[x][y] = ',';
    bool flag = Solve(gox, goy, 1);
    in[x][y] = '#';
    if (!flag) {
      printf("1");
      return 0;
    }
  }
  for (int i = 0; i < vec.size(); i++) {
    int x = vec[i].first, y = vec[i].second, gox = -1, goy = -1;
    for (int j = i + 1; j < vec.size(); j++) {
      if (i == j) continue;
      int x2 = vec[j].first, y2 = vec[j].second;
      if (i > 0)
        gox = vec[i - 1].first, goy = vec[i - 1].second;
      else if (i + 1 < j)
        gox = vec[i + 1].first, goy = vec[i + 1].second;
      else if (j - 1 > i)
        gox = vec[j - 1].first, goy = vec[j - 1].second;
      else if (j < vec.size() - 1)
        gox = vec[j + 1].first, goy = vec[j + 1].second;
      if (gox == -1 && goy == -1) continue;
      in[x][y] = ',', in[x2][y2] = ',';
      bool flag = Solve(gox, goy, 2);
      in[x][y] = '#', in[x2][y2] = '#';
      if (!flag) {
        printf("2");
        return 0;
      }
    }
  }
  printf("-1");
  return 0;
}
