#include <bits/stdc++.h>
using namespace std;
const int N = 52;
char a[N][N];
int n, m;
bool was[N][N];
bool go(int x, int y) {
  if (x < 0 || y < 0 || x >= n || y >= m) return false;
  if (was[x][y]) return false;
  was[x][y] = true;
  if (a[x][y] == '.') return false;
  go(x + 1, y);
  go(x, y + 1);
  go(x - 1, y);
  go(x, y - 1);
  return true;
}
bool con() {
  memset(was, 0, sizeof was);
  int comp = 0;
  for (int i = 0; i < ((int)(n)); ++i)
    for (int j = 0; j < ((int)(m)); ++j)
      if (go(i, j)) comp++;
  return comp <= 1;
}
int main() {
  srand(time(NULL));
  scanf("%d%d", &n, &m);
  for (int i = 0; i < ((int)(n)); ++i) scanf(" %s", a[i]);
  for (int i = 0; i < ((int)(n)); ++i)
    for (int j = 0; j < ((int)(m)); ++j)
      if (a[i][j] == '#') {
        a[i][j] = '.';
        if (!con()) {
          puts("1");
          return 0;
        }
        a[i][j] = '#';
      }
  for (int i1 = 0; i1 < ((int)(n)); ++i1)
    for (int j1 = 0; j1 < ((int)(m)); ++j1)
      if (a[i1][j1] == '#') {
        a[i1][j1] = '.';
        for (int i = 0; i < ((int)(i1 + 1)); ++i)
          for (int j = 0; j < ((int)(m)); ++j)
            if (a[i][j] == '#') {
              a[i][j] = '.';
              if (!con()) {
                puts("2");
                return 0;
              }
              a[i][j] = '#';
            }
        a[i1][j1] = '#';
      }
  puts("-1");
  return 0;
}
