#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
int n, m, dfsCount;
char s[55][55];
bool vis[55][55];
bool inside(int x, int y) { return 0 <= x && x < n && 0 <= y && y < m; }
void dfs(int x, int y) {
  if (!inside(x, y) || vis[x][y] || s[x][y] != '#') return;
  vis[x][y] = true;
  dfsCount++;
  for (int i = 0, _n = (4); i < _n; i++) dfs(x + dx[i], y + dy[i]);
}
int main() {
  int counter = 0, res = 2;
  scanf(" %d %d ", &n, &m);
  for (int i = 0, _n = (n); i < _n; i++) {
    scanf(" %s ", s[i]);
    for (int j = 0, _n = (m); j < _n; j++)
      if (s[i][j] == '#') counter++;
  }
  if (counter <= 2) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < n && res == 2; i++)
    for (int j = 0, _n = (m); j < _n; j++)
      if (s[i][j] == '#') {
        s[i][j] = '.';
        dfsCount = 0;
        for (int x = 0, _n = (n); x < _n; x++) {
          for (int y = 0, _n = (m); y < _n; y++)
            if (s[x][y] == '#') {
              memset(vis, false, sizeof(vis));
              dfs(x, y);
              break;
            }
          if (dfsCount) break;
        }
        if (dfsCount != counter - 1) {
          res = 1;
          break;
        }
        s[i][j] = '#';
      }
  printf("%d\n", res);
  return 0;
}
