#include <bits/stdc++.h>
using namespace std;
void dfss(vector<vector<int> > &a, int i, int j, list<pair<int, int> > b) {
  a[i][j] = 2;
  pair<int, int> t;
  t.first = i;
  t.second = j;
  b.push_back(t);
  while (b.size()) {
    i = b.front().first;
    j = b.front().second;
    if (i > 0 && a[i - 1][j] == 1) {
      a[i - 1][j] = 2;
      t.first = i - 1;
      t.second = j;
      b.push_back(t);
    }
    if (j > 0 && a[i][j - 1] == 1) {
      a[i][j - 1] = 2;
      t.first = i;
      t.second = j - 1;
      b.push_back(t);
    }
    if (j < (a[0].size() - 1) && a[i][j + 1] == 1) {
      a[i][j + 1] = 2;
      t.first = i;
      t.second = j + 1;
      b.push_back(t);
    }
    if (i < (a.size() - 1) && a[i + 1][j] == 1) {
      a[i + 1][j] = 2;
      t.first = i + 1;
      t.second = j;
      b.push_back(t);
    }
    b.pop_front();
  }
}
bool dfs(vector<vector<int> > a, int i, int j) {
  a[i][j] = 0;
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < a[0].size(); j++) {
      if (a[i][j] == 1) {
        list<pair<int, int> > b;
        dfss(a, i, j, b);
        i = a.size();
        j = a[0].size();
      }
    }
  }
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < a[0].size(); j++) {
      if (a[i][j] == 1) return true;
    }
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > a;
  vector<int> b;
  int sum = 0;
  for (int j = 0; j < n; j++) {
    char c;
    scanf("%c", &c);
    for (int i = 0; i < m; i++) {
      scanf("%c", &c);
      if (c == '#') {
        b.push_back(1);
        sum++;
      }
      if (c == '.') {
        b.push_back(0);
      }
    }
    a.push_back(b);
    b.clear();
  }
  if (sum < 3) {
    printf("-1");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == 1) {
        bool res = dfs(a, i, j);
        if (res) {
          printf("1");
          return 0;
        }
      }
    }
  }
  printf("2");
  return 0;
}
