#include <bits/stdc++.h>
using namespace std;
char c[55][55];
bool vis[55][55];
int n, m, nums;
int gox[4] = {0, 0, -1, 1};
int goy[4] = {1, -1, 0, 0};
bool judge(int a, int b) {
  if (a >= 0 && b >= 0 && a < n && b < m) return 1;
  return 0;
}
void dfs(int x, int y) {
  nums++;
  int a, b;
  for (int i = 0; i < 4; i++) {
    a = x + gox[i];
    b = y + goy[i];
    if (vis[a][b] == 0 && c[a][b] == '#' && judge(a, b)) {
      vis[a][b] = 1;
      dfs(a, b);
    }
  }
}
int main() {
  int num = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", c[i]);
    for (int j = 0; j < m; j++) {
      if (c[i][j] == '#') num++;
    }
  }
  if (num < 3)
    puts("-1");
  else {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (c[i][j] == '#') {
          nums = 0;
          memset(vis, 0, sizeof(vis));
          vis[i][j] = 1;
          bool flag = 0;
          for (int k = 0; k < n; k++) {
            for (int u = 0; u < m; u++) {
              if (c[k][u] == '#' && vis[k][u] == 0) {
                vis[k][u] = 1;
                dfs(k, u);
                flag = 1;
                break;
              }
            }
            if (flag) break;
          }
          if (nums != num - 1) {
            puts("1");
            return 0;
          }
        }
      }
    }
    puts("2");
  }
}
