#include <bits/stdc++.h>
using namespace std;
int vis[51][51];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
int cnt, n, m;
char arr[51][51];
bool isvalid(int x, int y) {
  if (x >= 0 && y >= 0 && x < n && y < m)
    return true;
  else
    return false;
}
void dfs(int x, int y) {
  cnt++;
  int nx, ny;
  for (long long int i = 0; i < 4; i++) {
    nx = dx[i] + x;
    ny = dy[i] + y;
    if (isvalid(nx, ny) && !vis[nx][ny] && arr[nx][ny] == '#') {
      vis[nx][ny] = 1;
      dfs(nx, ny);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  int tot = 0;
  for (long long int i = 0; i < n; i++)
    for (long long int j = 0; j < m; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == '#') tot++;
    }
  if (tot < 3) {
    cout << -1 << endl;
    return 0;
  }
  for (long long int i = 0; i < n; i++)
    for (long long int j = 0; j < m; j++) {
      if (arr[i][j] == '#') {
        memset(vis, 0, sizeof(vis));
        vis[i][j] = 1;
        cnt = 0;
        for (long long int p = 0; p < n; p++)
          for (long long int q = 0; q < m; q++) {
            if (arr[p][q] == '#' && !vis[p][q]) {
              vis[p][q] = 1;
              dfs(p, q);
              goto loop;
            }
          }
      loop:;
        if (cnt != tot - 1) {
          cout << 1 << endl;
          return 0;
        }
      }
    }
  cout << 2 << endl;
  return 0;
}
