#include <bits/stdc++.h>
using namespace std;
string s, ss;
int n, m, cnt;
char c[60][60];
bool vis[60][60];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool valid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
void dfs(int x, int y) {
  vis[x][y] = 1;
  cnt++;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (valid(nx, ny) && !vis[nx][ny] && c[nx][ny] == '#') dfs(nx, ny);
  }
}
int main() {
  cin >> n >> m;
  int x, y;
  vector<pair<int, int>> v;
  int num = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c[i][j];
      if (c[i][j] == '#') {
        v.push_back({i, j});
        num++, x = i, y = j;
      }
    }
  }
  if (num <= 2) {
    cout << "-1";
    return 0;
  }
  int ans = 2;
  for (int i = 0; i < num; i++) {
    memset(vis, 0, sizeof(vis));
    cnt = 0;
    c[v[i].first][v[i].second] = '.';
    dfs(x, y);
    if (cnt != num - 1) ans = 1;
    c[v[i].first][v[i].second] = '#';
    x = v[i].first, y = v[i].second;
  }
  cout << ans;
}
