#include <bits/stdc++.h>
bool a[51][51], used[51][51];
int n, m;
void dfs(int i, int j) {
  used[i][j] = true;
  if (i != n - 1 && a[i + 1][j] && !used[i + 1][j]) dfs(i + 1, j);
  if (i != 0 && a[i - 1][j] && !used[i - 1][j]) dfs(i - 1, j);
  if (j != m - 1 && a[i][j + 1] && !used[i][j + 1]) dfs(i, j + 1);
  if (j != 0 && a[i][j - 1] && !used[i][j - 1]) dfs(i, j - 1);
}
int main() {
  int S = 0, i1, j1, i2, j2;
  scanf("%d %d\n", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char c;
      scanf("%c", &c);
      if (c == '#') {
        a[i][j] = 1;
        i1 = i;
        j1 = j;
        S++;
      } else
        a[i][j] = 0;
    }
    scanf("\n");
  }
  if (S <= 2) {
    printf("-1");
    return 0;
  }
  if (S == 3) {
    printf("1");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    bool f = false;
    ;
    for (int j = 0; j < m; j++)
      if (a[i][j]) {
        i2 = i;
        j2 = j;
        f = true;
        break;
      }
    if (f) break;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j]) {
        a[i][j] = 0;
        memset(used, 0, sizeof(used));
        if (i == i1 && j == j1)
          dfs(i2, j2);
        else
          dfs(i1, j1);
        for (int i_ = 0; i_ < n; i_++)
          for (int j_ = 0; j_ < m; j_++)
            if (a[i_][j_])
              if (!used[i_][j_]) {
                printf("1");
                return 0;
              }
        a[i][j] = 1;
      }
  printf("2");
  return 0;
}
