#include <bits/stdc++.h>
using namespace std;
struct FAU {
  vector<int> p;
  vector<int> r;
  FAU(int n) {
    p.resize(n, -1);
    r.resize(n, 0);
  }
  int Find(int x) {
    if (p[x] == -1) return x;
    p[x] = Find(p[x]);
    return p[x];
  }
  bool Together(int x, int y) { return (Find(x) == Find(y)); }
  void Union(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y) return;
    if (r[x] > r[y])
      p[y] = x;
    else
      p[x] = y;
    if (r[x] == r[y]) ++r[y];
    return;
  }
};
bool isConnected(vector<vector<bool> > &T) {
  int n = (int)(T).size(), m = (int)(T[0]).size();
  FAU F(n * m);
  for (int i = (0); i <= (n - 1); ++i)
    for (int j = (0); j <= (m - 1); ++j)
      if (T[i][j]) {
        if (i < n - 1 && T[i + 1][j]) F.Union(i * m + j, (i + 1) * m + j);
        if (j < m - 1 && T[i][j + 1]) F.Union(i * m + j, i * m + j + 1);
      }
  int tmp = -1;
  for (int i = (0); i <= (n - 1); ++i)
    for (int j = (0); j <= (m - 1); ++j)
      if (T[i][j]) {
        if (tmp == -1)
          tmp = F.Find(i * m + j);
        else if (tmp != F.Find(i * m + j))
          return 0;
      }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<vector<bool> > T(n);
  for (int i = (0); i <= ((int)(T).size() - 1); ++i) T[i].resize(m);
  int cnt = 0;
  for (int i = (0); i <= (n - 1); ++i)
    for (int j = (0); j <= (m - 1); ++j) {
      char c;
      cin >> c;
      T[i][j] = (c == '#');
      cnt += T[i][j];
    }
  if (cnt <= 2) {
    cout << -1;
    return 0;
  }
  for (int i = (0); i <= (n - 1); ++i)
    for (int j = (0); j <= (m - 1); ++j)
      if (T[i][j]) {
        T[i][j] = 0;
        if (!isConnected(T)) {
          cout << 1;
          return 0;
        }
        T[i][j] = 1;
      }
  cout << 2;
  return 0;
}
