#include <bits/stdc++.h>
using namespace std;
bool vis[55][55];
char mat[55][55] = {0};
int n, m;
int dfs(int i, int j) {
  if (i == n + 1 || j == m + 1 || j == 0 || i == 0 || vis[i][j] ||
      mat[i][j] != '#')
    return 0;
  vis[i][j] = 1;
  return 1 + dfs(i + 1, j) + dfs(i - 1, j) + dfs(i, j + 1) + dfs(i, j - 1);
}
int main() {
  while (cin >> n >> m) {
    int sum = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cin >> mat[i][j];
        sum += (mat[i][j] == '#');
      }
    }
    bool b = 0;
    int ans = 2;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (mat[i][j] == '#') {
          memset(vis, 0, sizeof vis);
          mat[i][j] = '.';
          if (mat[i - 1][j] == '#') {
            if (sum - 1 != dfs(i - 1, j)) {
              ans = 1;
              i = j = 55;
              b = 1;
            }
          } else if (mat[i + 1][j] == '#') {
            if (sum - 1 != dfs(i + 1, j)) {
              ans = 1;
              i = j = 55;
              b = 1;
            }
          } else if (mat[i][j + 1] == '#') {
            if (sum - 1 != dfs(i, j + 1)) {
              ans = 1;
              i = j = 55;
              b = 1;
            }
          } else if (mat[i][j - 1] == '#') {
            if (sum - 1 != dfs(i, j - 1)) {
              ans = 1;
              i = j = 55;
              b = 1;
            }
          }
          mat[i][j] = '#';
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (mat[i][j] == '#') {
          int tmp = (mat[i - 1][j] == '#') + (mat[i + 1][j] == '#') +
                    (mat[i][j - 1] == '#') + (mat[i][j + 1] == '#');
          if (tmp >= 2) b = 1;
        }
      }
    }
    if (b)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
}
