#include <bits/stdc++.h>
using namespace std;
char s[60][60];
int a[60][60];
int vis[60][60];
int N, M;
int ans;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};
void dfs(int m, int n) {
  ans++;
  vis[m][n] = 1;
  for (int i = 0; i < 4; i++) {
    int nx = m + dx[i];
    int ny = n + dy[i];
    if (nx >= 1 && nx <= N && ny >= 0 && ny < M && s[nx][ny] == '#' &&
        vis[nx][ny] == -1) {
      dfs(nx, ny);
    }
  }
}
int main() {
  int k, d;
  int i, j;
  cin >> N >> M;
  for (i = 1; i <= N; i++) scanf("%s", s[i]);
  int t = 0;
  for (i = 1; i <= N; i++)
    for (j = 0; j < M; j++)
      if (s[i][j] == '#') t++;
  if (t <= 2) {
    printf("-1\n");
  } else {
    int check = 0;
    for (i = 1; i <= N; i++)
      for (j = 0; j < M; j++) {
        if (s[i][j] == '#' && !check) {
          s[i][j] = '.';
          memset(vis, -1, sizeof(vis));
          int flag = 0;
          for (k = 1; k <= N; k++)
            for (d = 0; d < M; d++)
              if (s[k][d] == '#' && !flag) {
                ans = 0;
                dfs(k, d);
                flag = 1;
                break;
              }
          if (ans != t - 1) {
            check = 1;
            break;
          }
          s[i][j] = '#';
        }
      }
    if (check == 1)
      printf("1\n");
    else
      printf("2\n");
  }
  return 0;
}
