#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) { cout << "NEXT\n"; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
template <typename... T>
void rd(T&... args) {
  ((cin >> args), ...);
}
template <typename... T>
void ps(T... args) {
  ((cout << args << ' '), ...);
  cout << '\n';
}
const long long MOD = 1e9 + 7, MOD1 = 998244353LL, MAX = 1e6 + 5;
const char nl = '\n';
const int INF = 1e9 + 5;
const int p = 31;
int n, m;
char c[55][55];
bool vis[55][55];
bool ok(int x, int y) {
  if (x >= 0 && x < n && y >= 0 && y < m) return 1;
  return 0;
}
bool ok1(int x, int y) {
  if (x >= 0 && x < n && y >= 0 && y < m && !vis[x][y] && c[x][y] == '#')
    return 1;
  return 0;
}
void dfs(int x, int y) {
  stack<pair<int, int> > s;
  s.push({x, y});
  vis[x][y] = 1;
  while (!s.empty()) {
    int nx = s.top().first, ny = s.top().second;
    s.pop();
    if (ok1(nx - 1, ny)) {
      vis[nx - 1][ny] = 1;
      s.push({nx - 1, ny});
    }
    if (ok1(nx + 1, ny)) {
      vis[nx + 1][ny] = 1;
      s.push({nx + 1, ny});
    }
    if (ok1(nx, ny - 1)) {
      vis[nx][ny - 1] = 1;
      s.push({nx, ny - 1});
    }
    if (ok1(nx, ny + 1)) {
      vis[nx][ny + 1] = 1;
      s.push({nx, ny + 1});
    }
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c[i][j];
    }
  }
  int cn_ = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (c[i][j] == '.') continue;
      cn_++;
    }
  }
  if (cn_ == 3) {
    cout << "1\n";
    return;
  }
  if (cn_ <= 2) {
    cout << "-1\n";
    return;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (c[i][j] == '.') continue;
      c[i][j] = '.';
      bool gu = 0;
      for (int k = 0; k < n; k++) {
        for (int l = 0; l < m; l++) {
          vis[k][l] = 0;
        }
      }
      for (int k = 0; k < n; k++) {
        for (int l = 0; l < m; l++) {
          if (c[k][l] == '#') {
            if (!gu)
              dfs(k, l);
            else if (!vis[k][l]) {
              cout << "1\n";
              return;
            }
            gu = 1;
          }
        }
      }
      c[i][j] = '#';
    }
  }
  cout << "2\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int __ = 1;
  while (__--) {
    solve();
  }
  return 0;
}
