#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > cells;
pair<int, int> operator+(const pair<int, int>& a, const pair<int, int>& b) {
  pair<int, int> res = a;
  res.first += b.first;
  res.second += b.second;
  return res;
}
int main(int argc, char** argv) {
  istream* is = &cin;
  ostream* os = &cout;
  if (argc >= 2) {
    is = new ifstream(argv[1]);
  }
  if (argc >= 3) {
    os = new ofstream(argv[2]);
  }
  int m, n, sq = 0;
  int res = 2;
  int root_child = 0;
  pair<int, int> ulc(-1, -1);
  *is >> n >> m;
  vector<vector<char> > a(n, vector<char>(m, 0));
  vector<vector<char> > v(n, vector<char>(m, 0));
  vector<vector<char> > chd(n, vector<char>(m, 0));
  vector<vector<int> > d(n, vector<int>(m, 0));
  vector<vector<int> > low(n, vector<int>(m, 0));
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) {
      *is >> a[i][j];
      if (a[i][j] == '#') {
        if (ulc.first < 0) ulc = make_pair(i, j);
        sq++;
      }
    }
  if (sq <= 2) {
    res = -1;
  } else {
    cells.push_back(make_pair(-1, 0));
    cells.push_back(make_pair(0, -1));
    cells.push_back(make_pair(1, 0));
    cells.push_back(make_pair(0, 1));
    stack<pair<pair<int, int>, pair<int, int> > > s;
    s.push(make_pair(ulc, make_pair(-1, -1)));
    int count = 1;
    int artcount = 0;
    while (!s.empty()) {
      pair<int, int> cell = s.top().first;
      pair<int, int> parent = s.top().second;
      int i = cell.first;
      int j = cell.second;
      if (v[i][j] == 0) {
        v[i][j] = 1;
        d[i][j] = count;
        low[i][j] = count;
        count++;
      }
      for (int k = 0; k < cells.size(); k++) {
        pair<int, int> child = cell + cells[k];
        int r = child.first;
        int c = child.second;
        if ((r >= 0) && (r < n) && (c >= 0) && (c < m)) {
          if (a[r][c] == '#') {
            if (0 == v[r][c]) {
              if (cell == ulc) root_child++;
              s.push(make_pair(child, cell));
              chd[i][j] |= (1 << k);
              break;
            } else if ((1 == v[r][c]) && (child != parent)) {
              low[i][j] = min(low[i][j], d[r][c]);
            }
          }
        }
      }
      if (s.top().first == cell) {
        v[i][j] = 2;
        if (cell != ulc) {
          for (int k = 0; k < cells.size(); k++) {
            pair<int, int> child = cell + cells[k];
            int r = child.first;
            int c = child.second;
            if ((r >= 0) && (r < n) && (c >= 0) && (c < m)) {
              if (a[r][c] == '#') {
                low[i][j] = min(low[i][j], low[r][c]);
                if (chd[i][j] & (1 << k)) {
                  if (low[r][c] >= d[i][j]) {
                    *os << 1 << endl;
                    return 0;
                  }
                }
              }
            }
          }
        }
        s.pop();
      }
      if (root_child > 1) {
        res = 1;
        break;
      }
    }
  }
  *os << res << endl;
  if (is != &cin) delete is;
  if (os != &cout) {
    os->flush();
    delete os;
  }
  return 0;
}
