#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n, m;
bool g[51][51];
char s[51];
int cells;
bool G[51][51];
bool used[51][51];
void dfs(int i, int j) {
  if (used[i][j]) return;
  used[i][j] = true;
  for (int k = 0, _n = (4); k < _n; ++k) {
    int i2 = i + dx[k];
    int j2 = j + dy[k];
    if (i2 < 0 || i2 >= n || j2 < 0 || j2 >= m || !G[i2][j2]) continue;
    dfs(i2, j2);
  }
}
bool good() {
  memset((used), (0), sizeof((used)));
  int cc = 0;
  for (int i = 0, _n = (n); i < _n; ++i)
    for (int j = 0, _n = (m); j < _n; ++j)
      if (G[i][j] && !used[i][j]) {
        dfs(i, j);
        cc++;
      }
  return cc >= 2;
}
void solution() {
  scanf("%d %d\n", &n, &m);
  for (int i = 0, _n = (n); i < _n; ++i) {
    gets(s);
    if (strlen(s) != m) throw 1;
    for (int j = 0, _n = (m); j < _n; ++j) {
      g[i][j] = (s[j] == '#');
      if (g[i][j]) cells++;
    }
  }
  memcpy(G, g, sizeof(g));
  if (good()) throw 1;
  if (cells <= 2) {
    puts("-1");
    return;
  }
  for (int i = 0, _n = (n); i < _n; ++i)
    for (int j = 0, _n = (m); j < _n; ++j)
      if (g[i][j]) {
        memcpy(G, g, sizeof(g));
        G[i][j] = false;
        if (good()) {
          puts("1");
          return;
        }
      }
  puts("2");
}
int main() {
  solution();
  return 0;
}
