#include <bits/stdc++.h>
using namespace std;
const int maxn = 40000;
vector<int> table[maxn];
bool mark[maxn];
int T, ent[maxn], up[maxn];
bool con = false;
void dfs(int v, int p = -1) {
  mark[v] = true;
  T++;
  ent[v] = up[v] = T;
  int children = 0;
  for (int i = 0; i < table[v].size(); ++i) {
    int u = table[v][i];
    if (u == p) continue;
    if (mark[u])
      up[v] = min(up[v], ent[u]);
    else {
      dfs(u, v);
      up[v] = min(up[v], up[u]);
      if ((up[u] >= ent[v]) && (p != -1)) con = true;
      ++children;
    }
  }
  if ((p == -1) && (children > 1)) con = true;
}
int main() {
  int mas[100][100];
  int n, m;
  cin >> n >> m;
  int count = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      char sign = 0;
      while ((sign != '#') && (sign != '.')) cin >> sign;
      mas[i][j] = (sign == '#' ? 1 : 0);
      count = mas[i][j] + count;
    }
  if (count <= 2) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (mas[i][j]) {
        if ((i > 0) && (mas[i - 1][j]))
          table[i * m + j].push_back(i * m + j - m);
        if ((i < n - 1) && (mas[i + 1][j]))
          table[i * m + j].push_back(i * m + j + m);
        if ((j > 0) && (mas[i][j - 1]))
          table[i * m + j].push_back(i * m + j - 1);
        if ((j < m - 1) && (mas[i][j + 1]))
          table[i * m + j].push_back(i * m + j + 1);
      }
  T = 0;
  for (int i = 0; i < n * m; ++i) mark[i] = false;
  for (int i = 0; i < n * m; ++i)
    for (int j = 0; j < m; ++j)
      if (mas[i][j]) {
        dfs(i * m + j);
        cout << (con ? "1" : "2") << endl;
        return 0;
      }
}
