#include <bits/stdc++.h>
namespace Suhaib_Templates {
using namespace std;
const long double PI = acos(-1);
const int di[8] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dj[8] = {1, -1, 0, 0, 1, -1, 1, -1};
long long FirstTrue(long long l, long long r, function<bool(long long)> f) {
  while (l < r) {
    long long mid = l + (r - l) / 2;
    f(mid) ? r = mid : l = mid + 1;
  }
  return l;
}
long long LastTrue(long long l, long long r, function<bool(long long)> f) {
  while (l < r) {
    long long mid = l + (r - l + 1) / 2;
    f(mid) ? l = mid : r = mid - 1;
  }
  return l;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
template <class T>
void re(complex<T>& x);
template <class T1, class T2>
void re(pair<T1, T2>& p);
template <class T>
void re(vector<T>& a);
template <class T, size_t SZ>
void re(array<T, SZ>& a);
template <class T>
void re(T& x) {
  cin >> x;
}
void re(double& x) {
  string t;
  re(t);
  x = stod(t);
}
void re(long double& x) {
  string t;
  re(t);
  x = stold(t);
}
template <class Arg, class... Args>
void re(Arg& first, Args&... rest) {
  re(first);
  re(rest...);
}
template <class T>
void re(complex<T>& x) {
  T a, b;
  re(a, b);
  x = cd(a, b);
}
template <class T1, class T2>
void re(pair<T1, T2>& p) {
  re(p.f, p.s);
}
template <class T>
void re(vector<T>& a) {
  for (int i = (0); i < ((int)a.size()); i += (1)) re(a[i]);
}
template <class T, size_t SZ>
void re(array<T, SZ>& a) {
  for (int i = (0); i < (SZ); i += (1)) re(a[i]);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T, size_t SZ>
void pr(const array<T, SZ>& x);
template <class T>
void pr(const vector<T>& x);
template <class T>
void pr(const set<T>& x);
template <class T1, class T2>
void pr(const map<T1, T2>& x);
template <class T>
void pr(const T& x) {
  cout << x;
}
template <class Arg, class... Args>
void pr(const Arg& first, const Args&... rest) {
  pr(first);
  pr(rest...);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x) {
  pr(x.first, ' ', x.second);
}
template <class T>
void prContain(const T& x) {
  for (auto& a : x) pr(a, ' ');
}
template <class T, size_t SZ>
void pr(const array<T, SZ>& x) {
  prContain(x);
}
template <class T>
void pr(const vector<T>& x) {
  prContain(x);
}
template <class T>
void pr(const set<T>& x) {
  prContain(x);
}
template <class T1, class T2>
void pr(const map<T1, T2>& x) {
  prContain(x);
}
void ps() { cout << '\n'; }
template <class Arg, class... Args>
void ps(const Arg& first, const Args&... rest) {
  pr(first, " ");
  ps(rest...);
}
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
}  // namespace Suhaib_Templates
using namespace Suhaib_Templates;
int n, m;
char c[50][50];
int visited[50][50], vid;
bool valid(int i, int j) {
  return i >= 0 && i < n && j >= 0 && j < m && visited[i][j] ^ vid &&
         c[i][j] ^ '.';
}
void dfs(int i, int j) {
  visited[i][j] = vid;
  for (int d = (0); d < (4); d += (1)) {
    int ni = i + di[d], nj = j + dj[d];
    if (valid(ni, nj)) {
      dfs(ni, nj);
    }
  }
}
void f(int n) {
  pr(n);
  exit(0);
}
void Suhaib_Sawalha() {
  re(n, m);
  int cnt = 0;
  for (int i = (0); i < (n); i += (1))
    for (int j = (0); j < (m); j += (1)) {
      re(c[i][j]);
      cnt += c[i][j] == '#';
    }
  if (cnt <= 2) f(-1);
  for (int i = (0); i < (n); i += (1))
    for (int j = (0); j < (m); j += (1)) {
      if (c[i][j] ^ '#') continue;
      c[i][j] = '.';
      ++vid;
      bool first = true;
      for (int x = (0); x < (n); x += (1))
        for (int y = (0); y < (m); y += (1)) {
          if (c[x][y] ^ '.' && visited[x][y] ^ vid) {
            if (first)
              dfs(x, y);
            else
              f(1);
            first = false;
          }
        }
      c[i][j] = '#';
    }
  f(2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Suhaib_Sawalha();
  return 0;
}
