#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
void fast() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
char grid[100][100];
vector<pair<int, int>> edg;
bool vis[50][50];
int n, m;
void dfs(int x, int y) {
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int u = dx[i] + x, v = dy[i] + y;
    if (u < 0 || v < 0 || u == n || v == m || grid[u][v] == '.' || vis[u][v])
      continue;
    dfs(u, v);
  }
}
int main() {
  fast();
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
      if (grid[i][j] == '#') edg.push_back({i, j});
    }
  }
  for (auto x : edg) {
    memset(vis, 0, sizeof vis);
    int cnt = 0;
    grid[x.first][x.second] = '.';
    for (auto v : edg) {
      if (v.first == x.first && v.second == x.second) continue;
      if (vis[v.first][v.second]) continue;
      cnt++;
      dfs(v.first, v.second);
    }
    if (cnt > 1) return cout << 1 << "\n", 0;
    ;
    grid[x.first][x.second] = '#';
  }
  if (edg.size() <= 2) return cout << -1 << "\n", 0;
  ;
  return cout << 2 << "\n", 0;
  ;
}
