#include <bits/stdc++.h>
using namespace std;
const int inv = numeric_limits<int>::max();
const int minv = numeric_limits<int>::min();
const int max_n = 55, max_m = 55;
int n, m;
char ip[max_n + 2][max_m + 2];
int p[max_n + 2][max_m + 2];
int v;
vector<int> adjl[max_n * max_m];
bool cutvertex;
bool visited[max_n * max_m] = {0};
int depth[max_n * max_m] = {0};
int low[max_n * max_m];
int nchs = 0;
void DFS(int vt) {
  visited[vt] = true;
  low[vt] = depth[vt] - 1;
  int vtnbr;
  for (int i = 0; i < adjl[vt].size(); ++i) {
    vtnbr = adjl[vt][i];
    if (not visited[vtnbr]) {
      if (vt == 0) ++nchs;
      depth[vtnbr] = depth[vt] + 1;
      visited[vtnbr] = true;
      DFS(vtnbr);
      low[vt] = min(low[vt], low[vtnbr]);
      if (vt != 0 and low[vtnbr] == depth[vt]) cutvertex = true;
    } else if (depth[vtnbr] < depth[vt]) {
      low[vt] = min(low[vt], depth[vtnbr]);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  char ts[max_m + 10];
  for (int i = 0; i < n + 2; ++i) {
    if (i != 0 and i != n + 1) {
      scanf("%s", ts);
    }
    for (int j = 0; j < m + 2; ++j) {
      if (i == 0 or i == n + 1 or j == 0 or j == m + 1)
        ip[i][j] = '.';
      else {
        ip[i][j] = ts[j - 1];
      }
    }
  }
  int ct = 0;
  for (int i = 0; i < n + 2; ++i) {
    for (int j = 0; j < m + 2; ++j) {
      if (ip[i][j] == '#') {
        p[i][j] = ct;
        ++ct;
      } else {
        p[i][j] = -1;
      }
    }
  }
  v = ct;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (p[i][j] >= 0) {
        if (p[i - 1][j] >= 0) adjl[p[i][j]].push_back(p[i - 1][j]);
        if (p[i + 1][j] >= 0) adjl[p[i][j]].push_back(p[i + 1][j]);
        if (p[i][j - 1] >= 0) adjl[p[i][j]].push_back(p[i][j - 1]);
        if (p[i][j + 1] >= 0) adjl[p[i][j]].push_back(p[i][j + 1]);
      }
    }
  }
  if (v == 1 or v == 2)
    printf("-1\n");
  else {
    cutvertex = false;
    fill(visited, visited + v, false);
    depth[0] = 0;
    DFS(0);
    if (cutvertex or nchs > 1)
      printf("1\n");
    else
      printf("2\n");
  }
  return 0;
}
