#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 7;
int n, m;
char s[55][55];
int fix[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
bool vis[55][55];
int getnum(int x, int y) {
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    int fx = x + fix[i][0];
    int fy = y + fix[i][1];
    if (fx >= 1 && fx <= n && fy >= 0 && fy < m && s[fx][fy] == '#') {
      ans++;
    }
  }
  return ans;
}
void bfs(int x, int y) {
  vis[x][y] = 1;
  queue<pair<int, int>> q;
  q.push(make_pair(x, y));
  while (!q.empty()) {
    x = q.front().first;
    y = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int fx = x + fix[i][0];
      int fy = y + fix[i][1];
      if (fx >= 1 && fx <= n && fy >= 0 && fy < m && s[fx][fy] == '#' &&
          !vis[fx][fy]) {
        vis[fx][fy] = 1;
        q.push(make_pair(fx, fy));
      }
    }
  }
}
bool check() {
  int f = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '#') {
        if (f) {
          bfs(i, j);
          f = 0;
        } else {
          if (!vis[i][j]) return false;
        }
      }
    }
  }
  return true;
}
int main() {
  while (~scanf("%d %d", &n, &m)) {
    for (int i = 1; i <= n; i++) scanf("%s", s[i]);
    int cot = 0;
    int mi = 10;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < m; j++) {
        if (s[i][j] == '#') {
          cot++;
          mi = min(mi, getnum(i, j));
        }
      }
    }
    if (cot == 0 || cot == 1 || cot == 2)
      printf("-1\n");
    else {
      int f = 1;
      if (mi >= 2) {
        for (int i = 1; i <= n; i++) {
          for (int j = 0; j < m; j++) {
            if (s[i][j] == '#') {
              s[i][j] = '.';
              memset(vis, 0, sizeof(vis));
              if (!check()) {
                f = 0;
              }
              s[i][j] = '#';
            }
          }
          if (!f) break;
        }
      }
      if (f)
        printf("%d\n", mi);
      else
        printf("1\n");
    }
  }
  return 0;
}
