#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
int n, m;
char s[MAXN][MAXN];
bool mark[MAXN][MAXN];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
bool valid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
void dfs(int x, int y) {
  mark[x][y] = true;
  for (int i = 0; i < 4; ++i) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    if (valid(xx, yy) && !mark[xx][yy] && s[xx][yy] == '#') dfs(xx, yy);
  }
}
bool is_connected() {
  int x, y;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == '#') x = i, y = j;
      mark[i][j] = false;
    }
  dfs(x, y);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (s[i][j] == '#' && !mark[i][j]) return false;
  return true;
}
int main() {
  cin >> n >> m;
  int tot = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      cin >> s[i][j];
      tot += (s[i][j] == '#');
    }
  if (tot <= 2) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == '#') {
        s[i][j] = '.';
        if (!is_connected()) {
          cout << "1\n";
          cerr << i << ' ' << j << '\n';
          return 0;
        }
        s[i][j] = '#';
      }
    }
  cout << "2\n";
  return 0;
}
