#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[55][55];
int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
int vis[55][55];
int dfs(int i, int j) {
  int ret = 1;
  vis[i][j] = 1;
  for (int k = 0; k < 4; k++) {
    int nx = i + dx[k], ny = j + dy[k];
    if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] == '#' &&
        !vis[nx][ny])
      ret += dfs(nx, ny);
  }
  return ret;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    int tot = 0;
    for (int i = 0; i < n; i++) {
      scanf("%s", s[i]);
      for (int j = 0; j < m; j++)
        if (s[i][j] == '#') tot++;
    }
    int ans = -1;
    if (tot == 0 || tot == 1 || tot == 2) {
      puts("-1");
      continue;
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (s[i][j] == '#') {
          s[i][j] = '.';
          memset(vis, 0, sizeof(vis));
          int f = 1;
          int cc;
          for (int ni = 0; f && ni < n; ni++)
            for (int nj = 0; f && nj < m; nj++)
              if (s[ni][nj] == '#') {
                cc = dfs(ni, nj);
                f = 0;
              }
          if (cc + 1 < tot) ans = 1;
          s[i][j] = '#';
          int cnt = 0;
          for (int k = 0; k < 4; k++) {
            int nx = i + dx[k], ny = j + dy[k];
            if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] == '#')
              cnt++;
          }
          if (cnt + 1 == tot) continue;
          if (ans == -1 || cnt < ans) ans = cnt;
        }
    printf("%d\n", ans);
  }
}
