#include <bits/stdc++.h>
using namespace std;
const int N = 55;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
int n, m, cnt, cur;
char a[N][N], s[N][N];
bool vis[N][N];
inline void dfs(int x, int y) {
  vis[x][y] = 1;
  ++cur;
  for (int xx, yy, k = 0; k < 4; k++) {
    xx = x + dx[k], yy = y + dy[k];
    if (!(0 <= xx && xx < n && 0 <= yy && yy < m)) continue;
    if (!vis[xx][yy] && s[xx][yy] == '#') dfs(xx, yy);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", a[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] == '#') cnt++;
  if (cnt <= 2) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] == '#') {
        for (int u = 0; u < n; u++)
          for (int v = 0; v < m; v++) s[u][v] = a[u][v];
        s[i][j] = '.';
        cur = 0;
        memset(vis, 0, sizeof vis);
        try {
          for (int u = 0; u < n; u++)
            for (int v = 0; v < m; v++)
              if (s[u][v] == '#') {
                dfs(u, v);
                if (cur == cnt - 1)
                  throw -1;
                else {
                  throw 1;
                }
              }
        } catch (int res) {
          if (res == 1) {
            printf("1\n");
            return 0;
          }
        }
      }
  printf("2\n");
  return 0;
}
