#include <bits/stdc++.h>
using namespace std;
const int INF = ~(1 << 31);
inline int in() {
  int a;
  scanf("%d", &a);
  return a;
}
template <class T1, class T2>
inline pair<T1, T2> reverse_make_pair(T1 x, T2 y) {
  return pair<T1, T2>(y, x);
}
template <class T>
ostream& operator<<(ostream& out, const vector<T> a) {
  for (int i = 0; i < (int)a.size(); i++) out << a[i] << ' ';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const set<T> a) {
  int i = 0;
  while (a.begin() + i != a.end()) {
    cout << *(a.begin() + i) << ' ';
    ++i;
  }
  return out;
}
double din() {
  double a;
  scanf("%lf", &a);
  return a;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const double eps = 1e-6;
int logbin(int a) {
  a--;
  int res = 1;
  while (a) a >>= 1, res <<= 1;
  return res;
}
int binpow(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1) res *= a;
    a *= a;
    n >>= 1;
  }
  return res;
}
struct treap {
  treap *l, *r;
  int c, y;
  int size;
  int sum;
  int lazy;
  treap() {
    l = r = NULL;
    size = 1;
  }
};
void recalc(treap*& a) {
  if (a == NULL) return;
  a->size = 1;
  if (a->l != NULL) {
    a->size += a->l->size;
  }
  if (a->r != NULL) {
    a->size += a->r->size;
  }
}
void merge(treap*& t, treap* l, treap* r) {
  if (l == NULL) return (void)(t = r);
  if (r == NULL) return (void)(t = l);
  if (r->y > l->y) {
    merge(r->l, l, r->l);
    t = r;
  } else {
    merge(l->r, l->r, r);
    t = l;
  }
  recalc(t);
}
void split(treap* v, int x, treap*& l, treap*& r) {
  if (v == NULL) {
    r = l = NULL;
    return;
  }
  int cur = 1;
  if (v->l != NULL) cur += v->l->size;
  if (cur <= x) {
    split(v->r, x - cur, v->r, r);
    l = v;
  } else {
    split(v->l, x, l, v->l);
    r = v;
  }
  recalc(v);
}
void dfs(treap* v) {
  if (v->l != NULL) dfs(v->l);
  cout << v->c << ' ';
  if (v->r != NULL) dfs(v->r);
}
vector<char> u;
int n, m;
pair<int, int> a(0, 0);
vector<string> g;
bool check() {
  vector<vector<int> > c(n + 2, vector<int>(m + 2, 0));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (g[i][j] == '#') {
        a.first = i;
        a.second = j;
        goto label;
      }
    }
  }
label:
  int s = 0;
  if (a.first == 0 && a.second == 0) return 0;
  c[a.first][a.second] = 1;
  queue<pair<int, int> > q;
  q.push(a);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (g[i][j] == '#') ++s;
  while (!q.empty()) {
    pair<int, int> b = q.front();
    q.pop();
    int i = b.first;
    int j = b.second;
    if (g[i + 1][j] == '#' && c[i + 1][j] == 0) {
      q.push(make_pair(i + 1, j));
      c[i + 1][j] = 1;
    }
    if (g[i - 1][j] == '#' && c[i - 1][j] == 0) {
      q.push(make_pair(i - 1, j));
      c[i - 1][j] = 1;
    }
    if (g[i][j + 1] == '#' && c[i][j + 1] == 0) {
      q.push(make_pair(i, j + 1));
      c[i][j + 1] = 1;
    }
    if (g[i][j - 1] == '#' && c[i][j - 1] == 0) {
      q.push(make_pair(i, j - 1));
      c[i][j - 1] = 1;
    }
  }
  if (s <= 1) return 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (g[i][j] == '#' && c[i][j] == 0) {
        return 1;
      }
    }
  }
  return 0;
}
int main() {
  n = in(), m = in();
  vector<string> gg;
  string ss = "";
  for (int i = 0; i < m; ++i) {
    ss += '.';
  }
  g.push_back(ss);
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    g.push_back(string("." + s + "."));
  }
  int cou = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (g[i][j] == '#') ++cou;
  if (cou <= 2) {
    cout << -1;
    return 0;
  }
  int res = INF;
  g.push_back(ss);
  gg = g;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m && res > 1; ++j) {
      if (1) {
        if (g[i][j] == '#') {
          g[i][j] = '.';
          if (check()) res = min(res, 1);
          g = gg;
        }
        if (g[i + 1][j] == '#') {
          g[i + 1][j] = '.';
          if (check()) res = min(res, 1);
          g = gg;
        }
        if (g[i - 1][j] == '#') {
          g[i - 1][j] = '.';
          if (check()) res = min(res, 1);
          g = gg;
        }
        if (g[i][j + 1] == '#') {
          g[i][j + 1] = '.';
          if (check()) res = min(res, 1);
          g = gg;
        }
        if (g[i][j - 1] == '#') {
          g[i][j - 1] = '.';
          if (check()) res = min(res, 1);
          g = gg;
        }
        if (res == 1) break;
        if (g[i][j - 1] == '#' && g[i][j + 1] == '#') {
          g[i][j - 1] = '.';
          g[i][j + 1] = '.';
          if (check()) res = min(res, 2);
          g = gg;
        }
        if (g[i][j - 1] == '#' && g[i - 1][j] == '#') {
          g[i][j - 1] = '.';
          g[i - 1][j] = '.';
          if (check()) res = min(res, 2);
          g = gg;
        }
        if (g[i - 1][j] == '#' && g[i][j + 1] == '#') {
          g[i - 1][j] = '.';
          g[i][j + 1] = '.';
          if (check()) res = min(res, 2);
          g = gg;
        }
        if (g[i + 1][j] == '#' && g[i - 1][j] == '#') {
          g[i - 1][j] = '.';
          g[i + 1][j] = '.';
          if (check()) res = min(res, 2);
          g = gg;
        }
        if (res <= 2) continue;
        if (g[i + 1][j] == '#' && g[i - 1][j] == '#' && g[i][j + 1] == '#') {
          g[i - 1][j] = '.';
          g[i + 1][j] = '.';
          g[i][j + 1] = '.';
          if (check()) res = min(res, 3);
          g = gg;
        }
        if (g[i + 1][j] == '#' && g[i - 1][j] == '#' && g[i][j - 1] == '#') {
          g[i - 1][j] = '.';
          g[i + 1][j] = '.';
          g[i][j - 1] = '.';
          if (check()) res = min(res, 3);
          g = gg;
        }
        if (g[i][j - 1] == '#' && g[i][j + 1] == '#' && g[i + 1][j] == '#') {
          g[i][j - 1] = '.';
          g[i][j + 1] = '.';
          g[i + 1][j] = '.';
          if (check()) res = min(res, 3);
          g = gg;
        }
        if (g[i][j - 1] == '#' && g[i][j + 1] == '#' && g[i - 1][j] == '#') {
          g[i][j - 1] = '.';
          g[i][j + 1] = '.';
          g[i - 1][j] = '.';
          if (check()) res = min(res, 3);
          g = gg;
        }
        if (res <= 3) continue;
        if (g[i][j - 1] == '#' && g[i][j + 1] == '#' && g[i - 1][j] == '#' &&
            g[i + 1][j]) {
          g[i][j - 1] = '.';
          g[i][j + 1] = '.';
          g[i - 1][j] = '.';
          g[i + 1][j] = '.';
          if (check()) res = min(res, 4);
          g = gg;
        }
      }
    }
  }
  cout << res;
  return 0;
}
