#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long M = 1e9 + 7;
template <typename T>
void print(vector<T>& v) {
  cout << "[";
  for (int i = 0; i < v.size(); ++i) {
    cout << v[i];
    if (i != v.size() - 1) cout << ", ";
  }
  cout << "]\n";
}
template <typename T>
void print(set<T>& v) {
  cout << "[";
  for (auto it : v) {
    cout << it;
    if (it != *v.rbegin()) cout << ", ";
  }
  cout << "]\n";
}
template <typename T, typename S>
void print(map<T, S>& v) {
  for (auto it : v) cout << it.first << " : " << it.second << "\n";
}
template <typename T, typename S>
void print(pair<T, S>& v) {
  cout << "( " << v.first << ", " << v.second << " )" << '\n';
}
template <typename T>
void print(T x) {
  cout << x << '\n';
}
int ans = 2;
vector<string> mat;
const int maxn = 56;
int n, m;
bool visited[maxn][maxn];
int tin[maxn][maxn], low[maxn][maxn];
int timer;
vector<int> mvi{1, -1, 0, 0};
vector<int> mvj{0, 0, 1, -1};
int comps = 0;
void dfs(int i, int j, int pi = -1, int pj = -1) {
  comps++;
  visited[i][j] = true;
  tin[i][j] = low[i][j] = timer++;
  int children = 0;
  for (int k = 0; k < 4; k++) {
    int ii = i + mvi[k], jj = j + mvj[k];
    if (ii >= n || ii < 0 || jj >= m || jj < 0 || mat[ii][jj] != '#') {
      continue;
    }
    if (ii == pi && jj == pj) continue;
    if (visited[ii][jj]) {
      low[i][j] = min(low[i][j], tin[ii][jj]);
    } else {
      dfs(ii, jj, i, j);
      low[i][j] = min(low[i][j], low[ii][jj]);
      if (low[ii][jj] >= tin[i][j] && pi != -1) {
        ans = 1;
      }
      ++children;
    }
  }
  if (pi == -1 && children > 1) {
    ans = 1;
  }
}
void find_cutpoints() {
  timer = 0;
  memset(visited, false, maxn * maxn);
  memset(tin, -1, maxn * maxn);
  memset(low, -1, maxn * maxn);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; j++) {
      if (!visited[i][j] && mat[i][j] == '#') {
        dfs(i, j);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    mat.push_back(s);
  }
  find_cutpoints();
  if (comps > 2)
    cout << ans << '\n';
  else
    cout << -1 << '\n';
}
