#include <bits/stdc++.h>
using namespace std;
int c[2501][3], dist[51][51], n, m, ans;
char s1[51][51];
bool b[51][51];
int main() {
  scanf("%d%d", &n, &m);
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s1[i]);
    for (int j = m; j; --j) s1[i][j] = s1[i][j - 1];
    for (int j = 1; j <= m; j++)
      if (s1[i][j] == '#') ++sum;
  }
  ans = 10;
  memset(b, true, sizeof(b));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (s1[i][j] == '#')
        for (int k = 0; k < 31; k++) {
          int cnt = 0;
          if (i > 1 && k & 1 && s1[i - 1][j] == '#') ++cnt, b[i - 1][j] = false;
          if (i < n && k & 2 && s1[i + 1][j] == '#') ++cnt, b[i + 1][j] = false;
          if (j > 1 && k & 4 && s1[i][j - 1] == '#') ++cnt, b[i][j - 1] = false;
          if (j < m && k & 8 && s1[i][j + 1] == '#') ++cnt, b[i][j + 1] = false;
          int now = k;
          if (cnt < ans) {
            memset(dist, 0, sizeof(dist));
            int k = 1;
            c[1][1] = i;
            c[1][2] = j;
            dist[i][j] = 1;
            for (int l = 1; l <= k; l++) {
              int x = c[l][1], y = c[l][2];
              if (!b[x][y]) continue;
              if (x > 1 && s1[x - 1][y] == '#' && !dist[x - 1][y])
                dist[x - 1][y] = 1, c[++k][1] = x - 1, c[k][2] = y;
              if (x < n && s1[x + 1][y] == '#' && !dist[x + 1][y])
                dist[x + 1][y] = 1, c[++k][1] = x + 1, c[k][2] = y;
              if (y > 1 && s1[x][y - 1] == '#' && !dist[x][y - 1])
                dist[x][y - 1] = 1, c[++k][1] = x, c[k][2] = y - 1;
              if (y < m && s1[x][y + 1] == '#' && !dist[x][y + 1])
                dist[x][y + 1] = 1, c[++k][1] = x, c[k][2] = y + 1;
            }
            if (k != sum) ans = cnt;
          }
          if (i > 1 && k & 1 && s1[i - 1][j] == '#') b[i - 1][j] = true;
          if (i < n && k & 2 && s1[i + 1][j] == '#') b[i + 1][j] = true;
          if (j > 1 && k & 4 && s1[i][j - 1] == '#') b[i][j - 1] = true;
          if (j < m && k & 8 && s1[i][j + 1] == '#') b[i][j + 1] = true;
        }
  if (ans != 10)
    printf("%d\n", ans);
  else
    printf("-1\n");
}
