#include <bits/stdc++.h>
using namespace std;
int n, m, k = 0;
char s[51][51];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int dfs(int i, int j) {
  int ans = 1;
  s[i][j] = 'x';
  for (int w = 0; w < 4; w++)
    if (s[i + dx[w]][j + dy[w]] == '#') ans += dfs(i + dx[w], j + dy[w]);
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> s[i][j];
      if (s[i][j] == '#') k++;
    }
  if (k == 1 || k == 2) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (s[i][j] == '#') {
        s[i][j] = '.';
        for (int w = 0; w < 4; w++)
          if (s[i + dx[w]][j + dy[w]] == '#')
            if (dfs(i + dx[w], j + dy[w]) != k - 1) {
              cout << 1;
              return 0;
            }
        for (int i1 = 1; i1 <= n; i1++)
          for (int j1 = 1; j1 <= m; j1++)
            if (s[i1][j1] == 'x') s[i1][j1] = '#';
        s[i][j] = '#';
      }
  cout << 2;
  return 0;
}
