#include <bits/stdc++.h>
using namespace std;
int n, m, adj[51][51], temp[51][51], cnt = 0;
int dfs(int x, int y) {
  if (temp[x][y] == -1) return 0;
  int tor = 1;
  temp[x][y] = -1;
  if ((x + 1) < n)
    if (temp[x + 1][y]) tor += dfs(x + 1, y);
  if ((x - 1) > -1)
    if (temp[x - 1][y]) tor += dfs(x - 1, y);
  if ((y + 1) < m)
    if (temp[x][y + 1]) tor += dfs(x, y + 1);
  if ((y - 1) > -1)
    if (temp[x][y - 1]) tor += dfs(x, y - 1);
  return tor;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < m; ++j) {
      if (s[j] == '#')
        adj[i][j] = 1, ++cnt;
      else
        adj[i][j] = 0;
    }
  }
  if (cnt < 3) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int w = 0; w < n; ++w) {
        for (int t = 0; t < m; ++t) temp[w][t] = adj[w][t];
      }
      if (adj[i][j]) {
        int xx = -1, yy = -1;
        temp[i][j] = 0;
        for (int w = 0; w < n; ++w) {
          if (xx != -1) break;
          for (int t = 0; t < m; ++t) {
            if (temp[w][t]) {
              xx = w, yy = t;
              break;
            }
          }
        }
        if (dfs(xx, yy) != (cnt - 1)) {
          puts("1");
          return 0;
        }
      }
    }
  }
  puts("2");
  return 0;
}
