#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long MOD = 998244353;
const double EPS = 1e-8;
const double PI = acos(-1.0);
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p) {
  cerr << "{";
  _print(p.first);
  cerr << ",";
  _print(p.second);
  cerr << "}";
}
template <class T>
void _print(vector<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(set<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(multiset<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v) {
  cerr << "[ ";
  for (auto i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
const int N = 55;
int g[N][N], visited[N][N];
vector<int> dx = {-1, 1, 0, 0};
vector<int> dy = {0, 0, -1, 1};
int n, m, timer;
int low[N][N], tin[N][N];
bool bridge = 0;
bool check(int x, int y, int n, int m) {
  return x >= 0 && y >= 0 && x < n && y < m;
}
void dfs(int ux, int uy, int px, int py) {
  low[ux][uy] = tin[ux][uy] = timer++;
  int c = 0;
  visited[ux][uy] = 1;
  for (int i = 0; i < 4; ++i) {
    int vx = ux + dx[i];
    int vy = uy + dy[i];
    if (vx == px && vy == py) continue;
    if (check(vx, vy, n, m) && g[vx][vy] == 1) {
      if (visited[vx][vy]) {
        low[ux][uy] = min(low[ux][uy], tin[vx][vy]);
      } else {
        pair<int, int> d = {ux, uy}, d2 = {vx, vy};
        dfs(vx, vy, ux, uy);
        low[ux][uy] = min(low[ux][uy], low[vx][vy]);
        c++;
        if (low[vx][vy] >= tin[ux][uy] && px != -1) {
          bridge = 1;
          ;
          ;
          ;
          ;
        }
      }
    }
  }
  if (px == -1 && c > 1) {
    bridge = 1;
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      char c;
      cin >> c;
      int id = 0;
      if (c == '#') id = 1;
      g[i][j] = id;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (g[i][j] == 1) {
        cnt++;
        if (!visited[i][j]) {
          dfs(i, j, -1, -1);
          if (bridge) {
            cout << "1\n";
            return;
          }
        }
      }
    }
  }
  if (cnt <= 2) {
    cout << "-1\n";
    return;
  }
  cout << "2\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
