#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long r[4] = {-1, 0, 1, 0};
long long c[4] = {0, 1, 0, -1};
char grid[51][51];
bool vis[51][51];
vector<pair<long long int, long long int>> artPoints;
long long t = 1;
long long id[51][51];
long long low[51][51];
long long isSafe(long long x, long long y, long long n, long long m) {
  return (x >= 0 && x < n && y >= 0 && y < m);
}
bool bfs() {
  long long x = -1, y = -1;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (grid[i][j] == '#') {
        x = i, y = j;
      }
    }
  }
  if (x == -1) return 0;
  queue<pair<long long, long long>> q;
  q.push({x, y});
  vector<vector<bool>> vis(n, vector<bool>(m, 0));
  vis[x][y] = 1;
  while (!q.empty()) {
    pair<long long int, long long int> cur = q.front();
    q.pop();
    for (long long int i = 0; i < 4; i++) {
      if (isSafe(cur.first + r[i], cur.second + c[i], n, m) &&
          !vis[cur.first + r[i]][cur.second + c[i]] &&
          grid[cur.first + r[i]][cur.second + c[i]] == '#') {
        vis[cur.first + r[i]][cur.second + c[i]] = 1;
        q.push({cur.first + r[i], cur.second + c[i]});
      }
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (grid[i][j] == '#' && !vis[i][j]) return 1;
    }
  }
  return 0;
}
void findArt(long long x, long long y, long long parx = -1,
             long long pary = -1) {
  vis[x][y] = 1;
  id[x][y] = t++;
  low[x][y] = id[x][y];
  long long childs = 0;
  for (long long int i = 0; i < 4; i++) {
    if (x + r[i] == parx && y + c[i] == pary) continue;
    if (isSafe(x + r[i], y + c[i], n, m) && grid[x + r[i]][y + c[i]] == '#') {
      if (!vis[x + r[i]][y + c[i]]) {
        childs++;
        findArt(x + r[i], y + c[i], x, y);
        if (childs > 1 && parx == -1) artPoints.push_back({x, y});
        low[x][y] = min(low[x][y], low[x + r[i]][y + c[i]]);
        if (parx != -1 && low[x + r[i]][y + c[i]] >= id[x][y]) {
          artPoints.push_back({x, y});
        }
      } else {
        low[x][y] = min(low[x][y], low[x + r[i]][y + c[i]]);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  long long cnt = 0;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> grid[i][j];
      if (grid[i][j] == '#') {
        cnt++;
      }
    }
  }
  if (cnt <= 2) {
    cout << -1;
    return 0;
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (grid[i][j] == '#' && !vis[i][j]) {
        findArt(i, j);
      }
    }
  }
  if (artPoints.size() > 0)
    cout << 1;
  else
    cout << 2;
}
