#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T checkmin(T &a, T b) {
  return (a < b) ? a : a = b;
}
template <class T>
inline T checkmax(T &a, T b) {
  return (a > b) ? a : a = b;
}
template <class T>
T GCD(T a, T b) {
  if (a < 0) return GCD(-a, b);
  if (b < 0) return GCD(a, -b);
  return (a == 0) ? b : GCD(b % a, a);
}
template <class T>
T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return (a == 0 || b == 0) ? 0 : a / GCD(a, b) * b;
}
template <class T>
inline T sqr(T X) {
  return X * X;
}
namespace Poor {
const int MaxiN = 55;
int N, M, Ans;
char Map[MaxiN][MaxiN];
bool Vis[MaxiN][MaxiN];
bool InRange(int X, int Y) { return 0 <= X && X < N && 0 <= Y && Y < M; }
bool Check() {
  int Cnt = 0;
  deque<pair<int, int> > Q;
  memset(Vis, 0, sizeof(Vis));
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j)
      if (Map[i][j] == '#' && !Vis[i][j]) {
        ++Cnt;
        if (Cnt >= 2) return 1;
        Q.push_back(make_pair(i, j));
        Vis[i][j] = 1;
        while (!Q.empty()) {
          pair<int, int> Cur = Q.front();
          Q.pop_front();
          for (int a = -1; a <= 1; ++a)
            for (int b = -1; b <= 1; ++b)
              if (abs(a) + abs(b) == 1) {
                int NX = Cur.first + a, NY = Cur.second + b;
                if (InRange(NX, NY) && Map[NX][NY] == '#' && !Vis[NX][NY]) {
                  Vis[NX][NY] = 1;
                  Q.push_back(make_pair(NX, NY));
                }
              }
        }
      }
  return 0;
}
void Run() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; ++i) scanf("%s", Map[i]);
  Ans = 2;
  int Cnt = 0;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j) Cnt += (Map[i][j] == '#');
  if (Check()) Ans = 0;
  if (Cnt <= 2) Ans = -1;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j)
      if (Ans == 2 && Map[i][j] == '#') {
        Map[i][j] = '.';
        if (Check()) Ans = 1;
        Map[i][j] = '#';
      }
  printf("%d\n", Ans);
}
}  // namespace Poor
int main() {
  Poor::Run();
  return 0;
}
