#include <bits/stdc++.h>
using namespace std;
vector<vector<bool> > mas;
int Number = 0;
int n, m;
bool bfs(int t, int r, int Xep, int Xep2) {
  vector<vector<bool> > use;
  use.resize(n + 2);
  for (int i = 0; i < n + 2; i++) {
    use[i].resize(m + 2);
    for (int j = 0; j < m + 2; j++) {
      use[i][j] = false;
    }
  }
  use[t][r] = true;
  use[Xep][Xep2] = true;
  vector<pair<int, int> > bfs;
  pair<int, int> A;
  A = make_pair(t, r);
  bfs.push_back(A);
  for (int k = 0; k != bfs.size(); k++) {
    if (mas[bfs[k].first - 1][bfs[k].second] == true &&
        use[bfs[k].first - 1][bfs[k].second] == false) {
      A = make_pair(bfs[k].first - 1, bfs[k].second);
      bfs.push_back(A);
      use[bfs[k].first - 1][bfs[k].second] = true;
    }
    if (mas[bfs[k].first][bfs[k].second - 1] == true &&
        use[bfs[k].first][bfs[k].second - 1] == false) {
      A = make_pair(bfs[k].first, bfs[k].second - 1);
      bfs.push_back(A);
      use[bfs[k].first][bfs[k].second - 1] = true;
    }
    if (mas[bfs[k].first + 1][bfs[k].second] == true &&
        use[bfs[k].first + 1][bfs[k].second] == false) {
      A = make_pair(bfs[k].first + 1, bfs[k].second);
      bfs.push_back(A);
      use[bfs[k].first + 1][bfs[k].second] = true;
    }
    if (mas[bfs[k].first][bfs[k].second + 1] == true &&
        use[bfs[k].first][bfs[k].second + 1] == false) {
      A = make_pair(bfs[k].first, bfs[k].second + 1);
      bfs.push_back(A);
      use[bfs[k].first][bfs[k].second + 1] = true;
    }
  }
  if (bfs.size() == Number - 1) {
    return true;
  } else {
    return false;
  }
}
int main() {
  cin >> n >> m;
  char c;
  mas.resize(n + 2);
  for (int i = 1; i <= n; i++) {
    mas[i].resize(m + 2);
    mas[i][0] = false;
    mas[i][m + 1] = false;
    for (int j = 1; j <= m; j++) {
      cin >> c;
      if (c == '#') {
        mas[i][j] = true;
        Number++;
      } else {
        mas[i][j] = false;
      }
    }
  }
  for (int j = 0; j < m + 2; j++) {
    mas[0].resize(m + 2);
    mas[n + 1].resize(m + 2);
    mas[0][j] = false;
    mas[n + 1][j] = false;
  }
  if (Number == 1 || Number == 2) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mas[i][j] == true) {
        if (mas[i - 1][j] == true) {
          if (!bfs(i - 1, j, i, j)) {
            cout << 1;
            return 0;
          }
        }
        if (mas[i][j - 1] == true) {
          if (!bfs(i, j - 1, i, j)) {
            cout << 1;
            return 0;
          }
        }
        if (mas[i + 1][j] == true) {
          if (!bfs(i + 1, j, i, j)) {
            cout << 1;
            return 0;
          }
        }
        if (mas[i][j + 1] == true) {
          if (!bfs(i, j + 1, i, j)) {
            cout << 1;
            return 0;
          }
        }
      }
    }
  }
  cout << 2;
  return 0;
}
