#include <bits/stdc++.h>
using namespace std;
void rec(vector<vector<int> >& map, int i, int j, int cnt) {
  if (map[i][j] != 0) return;
  map[i][j] = cnt;
  if (i > 0) rec(map, i - 1, j, cnt);
  if (i + 1 < map.size()) rec(map, i + 1, j, cnt);
  if (j > 0) rec(map, i, j - 1, cnt);
  if (j + 1 < map[0].size()) rec(map, i, j + 1, cnt);
  if (i > 0 && j > 0) rec(map, i - 1, j - 1, cnt);
  if (i > 0 && j + 1 < map[0].size()) rec(map, i - 1, j + 1, cnt);
  if (i + 1 < map.size() && j > 0) rec(map, i + 1, j - 1, cnt);
  if (i + 1 < map.size() && j + 1 < map.size()) rec(map, i + 1, j + 1, cnt);
}
void rec2(vector<vector<int> >& map, int i, int j, int cnt) {
  if (map[i][j] != 0) return;
  map[i][j] = cnt;
  if (i > 0) rec(map, i - 1, j, cnt);
  if (i + 1 < map.size()) rec(map, i + 1, j, cnt);
  if (j > 0) rec(map, i, j - 1, cnt);
  if (j + 1 < map[0].size()) rec(map, i, j + 1, cnt);
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<vector<int> > map(n + 2, vector<int>(m + 2, 0));
  int k = 0;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      char tmp;
      while (scanf("%c", &tmp) && tmp != '.' && tmp != '#')
        ;
      if (tmp == '.')
        map[i][j] = 0;
      else {
        map[i][j] = -1;
        k++;
      }
    }
  }
  if (k < 3) {
    cout << -1 << endl;
    return 0;
  }
  int cnt = 1;
  for (int i = 0; i < n + 2; i++) {
    for (int j = 0; j < m + 2; j++) {
      if (map[i][j] != 0) continue;
      rec(map, i, j, cnt++);
    }
  }
  int ans = 2;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      if (map[i][j] == -1) {
        int con = (bool)map[i + 1][j] + (bool)map[i - 1][j] +
                  (bool)map[i][j + 1] + (bool)map[i][j - 1];
        if (con > 1) {
          vector<vector<int> > used(3, vector<int>(3, 0));
          vector<int> set;
          for (int x = -1; x < 2; x++) {
            for (int y = -1; y < 2; y++) {
              if (map[i + x][j + y] == -1) used[x + 1][y + 1] = 1;
            }
          }
          for (int x = -1; x < 2; x++) {
            for (int y = -1; y < 2; y++) {
              if (map[i + x][j + y] == -1 || used[x + 1][y + 1]) continue;
              for (int it = 0; it < set.size(); it++)
                if (map[i + x][j + y] == set[it]) ans = 1;
              set.push_back(map[i + x][j + y]);
              rec2(used, x + 1, y + 1, 1);
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
