#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const long long INF64 = (long long)1e18;
const long double eps = 1e-9;
const long double pi = 3.14159265358979323846;
bool ineedoutputfile = false;
int n, m;
char f[50][50];
bool used[50][50];
bool ok(int x, int y) {
  if ((x >= 0) && (y >= 0) && (x < n) && (y < m))
    return (f[x][y] == '#' && !used[x][y]);
  return false;
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
void dfs(int x, int y) {
  used[x][y] = 1;
  for (int i = 0; i < int(4); ++i) {
    int nx = x + dx[i], ny = y + dy[i];
    if (ok(nx, ny)) dfs(nx, ny);
  }
}
bool check(int x, int y) {
  f[x][y] = '.';
  bool yes = true;
  for (int i = 0; i < int(n); ++i) {
    if (!yes) break;
    for (int j = 0; j < int(m); ++j)
      if (ok(i, j)) {
        dfs(i, j);
        yes = false;
        break;
      }
  }
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(m); ++j)
      if (ok(i, j)) return true;
  f[x][y] = '#';
  memset(used, 0, sizeof(used));
  return false;
}
int main() {
  cin >> n >> m;
  int cntF = 0;
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(m); ++j) {
      cin >> f[i][j];
      cntF += (f[i][j] == '#');
    }
  if (cntF <= 2) puts("-1"), exit(0);
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(m); ++j)
      if (ok(i, j) && check(i, j)) puts("1"), exit(0);
  puts("2");
}
