#include <bits/stdc++.h>
using namespace std;
int visited[51][51] = {0}, n, m;
char arr[51][51];
void fun(int i, int j) {
  if (visited[i][j] == 1 || i >= n + 1 || i <= 0 || j >= m + 1 || j <= 0)
    return;
  if (arr[i][j] == '#') {
    visited[i][j] = 1;
    fun(i - 1, j);
    fun(i + 1, j);
    fun(i, j - 1);
    fun(i, j + 1);
  }
}
int main() {
  int i, j, a, f1 = 0, f2 = 0, cnt = 0, cnt1 = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (j = 0; j < m; j++) {
      arr[i + 1][j + 1] = s[j];
      if (s[j] == '#') cnt1++;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      memset(visited, 0, sizeof visited);
      cnt = 0;
      if (arr[i][j] == '#') {
        arr[i][j] = '.';
        for (int k = 1; k <= n; k++) {
          for (int l = 1; l <= m; l++) {
            if (arr[k][l] == '#' && visited[k][l] == 0) {
              cnt++;
              fun(k, l);
            }
          }
        }
        arr[i][j] = '#';
        if (cnt >= 2) f1 = 1;
      }
    }
  }
  if (cnt1 <= 2)
    cout << -1;
  else if (f1 == 1)
    cout << 1;
  else
    cout << 2;
  return 0;
}
