#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2600;
vector<int> adj[MAXN];
int par[MAXN];
int low[MAXN];
int val[MAXN];
int ans;
int t;
char v[55][55];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int any_id = -1;
void dfs(int src) {
  low[src] = val[src] = t++;
  int count = 0;
  bool is_art = false;
  for (__typeof((adj[src]).begin()) it = (adj[src]).begin();
       it != (adj[src]).end(); ++it)
    if (*it != par[src]) {
      if (par[*it] == -1) {
        par[*it] = src;
        dfs(*it);
        low[src] = min(low[src], low[*it]);
        if (low[*it] >= val[src]) is_art = true;
        ++count;
      } else
        low[src] = min(low[src], val[*it]);
    }
  if (src == any_id && count > 1)
    ++ans;
  else if (src != any_id && is_art)
    ++ans;
}
int getid(int x, int y) {
  any_id = 50 * x + y;
  return 50 * x + y;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  int n, m;
  cin >> n >> m;
  int qtd = 0;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) {
      cin >> v[i][j];
      if (v[i][j] == '#') ++qtd;
    }
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j)
      if (v[i][j] == '#') {
        for (int k = 0; k < (4); ++k) {
          int nx = i + dx[k];
          int ny = j + dy[k];
          if (nx >= 0 && nx < n && ny >= 0 && ny < m && v[nx][ny] == '#') {
            adj[getid(i, j)].push_back(getid(nx, ny));
          }
        }
      }
  if (qtd <= 2) {
    cout << "-1\n";
    exit(0);
  }
  memset(par, -1, sizeof(par));
  par[any_id] = any_id;
  dfs(any_id);
  if (ans)
    printf("1\n");
  else
    printf("2\n");
  return 0;
}
