#include <bits/stdc++.h>
using namespace std;
int a[100][100];
int visited[100][100];
int n, m;
int fx[] = {-1, 0, 1, 0};
int fy[] = {0, 1, 0, -1};
int bfs(int sx, int sy) {
  memset(visited, 0, sizeof visited);
  visited[sx][sy] = 1;
  queue<pair<int, int> > q;
  q.push(make_pair(sx, sy));
  int total = 1;
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int ux = p.first;
    int uy = p.second;
    for (int i = 0; i < 4; i++) {
      int vx = ux + fx[i];
      int vy = uy + fy[i];
      if (vx >= 0 && uy >= 0 && vy < m && vx < n && visited[vx][vy] == 0 &&
          a[vx][vy] == 1) {
        total++;
        q.push(make_pair(vx, vy));
        visited[vx][vy] = 1;
        if (ux == sx && uy == sy) break;
      }
    }
  }
  return total;
}
int main() {
  cin >> n >> m;
  int cc = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char c;
      cin >> c;
      if (c == '#') {
        a[i][j] = 1;
        cc++;
      } else
        a[i][j] = 0;
    }
  }
  int flag = 2;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == 1) {
        int temp = bfs(i, j);
        if (temp != cc) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 1) break;
  }
  if (n == 1 && m <= 2) flag = -1;
  if (m == 1 && n <= 2) flag = -1;
  if (cc < 3) flag = -1;
  cout << flag << endl;
  return 0;
}
