You've gotten an n × m sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as A. Set A is connected. Your task is to find the minimum number of squares that we can delete from set A to make it not connected.

A set of painted squares is called connected, if for every two squares a and b from this set there is a sequence of squares from the set, beginning in a and ending in b, such that in this sequence any square, except for the last one, shares a common side with the square that follows next in the sequence. An empty set and a set consisting of exactly one square are connected by definition.

Input

The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the sizes of the sheet of paper. 

Each of the next n lines contains m characters — the description of the sheet of paper: the j-th character of the i-th line equals either "#", if the corresponding square is painted (belongs to set A), or equals "." if the corresponding square is not painted (does not belong to set A). It is guaranteed that the set of all painted squares A is connected and isn't empty.

Output

On the first line print the minimum number of squares that need to be deleted to make set A not connected. If it is impossible, print -1. 

Examples

Input

5 4
####
#..#
#..#
#..#
####


Output

2


Input

5 5
#####
#...#
#####
#...#
#####


Output

2

Note

In the first sample you can delete any two squares that do not share a side. After that the set of painted squares is not connected anymore.

The note to the second sample is shown on the figure below. To the left there is a picture of the initial set of squares. To the right there is a set with deleted squares. The deleted squares are marked with crosses. 

<image>
#include <bits/stdc++.h>
namespace Suhaib_Templates {
using namespace std;
const long double PI = acos(-1);
const int di[8] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dj[8] = {1, -1, 0, 0, 1, -1, 1, -1};
long long FirstTrue(long long l, long long r, function<bool(long long)> f) {
  while (l < r) {
    long long mid = l + (r - l) / 2;
    f(mid) ? r = mid : l = mid + 1;
  }
  return l;
}
long long LastTrue(long long l, long long r, function<bool(long long)> f) {
  while (l < r) {
    long long mid = l + (r - l + 1) / 2;
    f(mid) ? l = mid : r = mid - 1;
  }
  return l;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
template <class T>
void re(complex<T>& x);
template <class T1, class T2>
void re(pair<T1, T2>& p);
template <class T>
void re(vector<T>& a);
template <class T, size_t SZ>
void re(array<T, SZ>& a);
template <class T>
void re(T& x) {
  cin >> x;
}
void re(double& x) {
  string t;
  re(t);
  x = stod(t);
}
void re(long double& x) {
  string t;
  re(t);
  x = stold(t);
}
template <class Arg, class... Args>
void re(Arg& first, Args&... rest) {
  re(first);
  re(rest...);
}
template <class T>
void re(complex<T>& x) {
  T a, b;
  re(a, b);
  x = cd(a, b);
}
template <class T1, class T2>
void re(pair<T1, T2>& p) {
  re(p.f, p.s);
}
template <class T>
void re(vector<T>& a) {
  for (int i = (0); i < ((int)a.size()); i += (1)) re(a[i]);
}
template <class T, size_t SZ>
void re(array<T, SZ>& a) {
  for (int i = (0); i < (SZ); i += (1)) re(a[i]);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T, size_t SZ>
void pr(const array<T, SZ>& x);
template <class T>
void pr(const vector<T>& x);
template <class T>
void pr(const set<T>& x);
template <class T1, class T2>
void pr(const map<T1, T2>& x);
template <class T>
void pr(const T& x) {
  cout << x;
}
template <class Arg, class... Args>
void pr(const Arg& first, const Args&... rest) {
  pr(first);
  pr(rest...);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x) {
  pr(x.first, ' ', x.second);
}
template <class T>
void prContain(const T& x) {
  for (auto& a : x) pr(a, ' ');
}
template <class T, size_t SZ>
void pr(const array<T, SZ>& x) {
  prContain(x);
}
template <class T>
void pr(const vector<T>& x) {
  prContain(x);
}
template <class T>
void pr(const set<T>& x) {
  prContain(x);
}
template <class T1, class T2>
void pr(const map<T1, T2>& x) {
  prContain(x);
}
void ps() { cout << '\n'; }
template <class Arg, class... Args>
void ps(const Arg& first, const Args&... rest) {
  pr(first, " ");
  ps(rest...);
}
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
}  // namespace Suhaib_Templates
using namespace Suhaib_Templates;
int n, m;
char c[50][50];
int visited[50][50], vid;
bool valid(int i, int j) {
  return i >= 0 && i < n && j >= 0 && j < m && visited[i][j] ^ vid &&
         c[i][j] ^ '.';
}
void dfs(int i, int j) {
  visited[i][j] = vid;
  for (int d = (0); d < (4); d += (1)) {
    int ni = i + di[d], nj = j + dj[d];
    if (valid(ni, nj)) {
      dfs(ni, nj);
    }
  }
}
void f(int n) {
  pr(n);
  exit(0);
}
void Suhaib_Sawalha() {
  re(n, m);
  int cnt = 0;
  for (int i = (0); i < (n); i += (1))
    for (int j = (0); j < (m); j += (1)) {
      re(c[i][j]);
      cnt += c[i][j] == '#';
    }
  if (cnt <= 2) f(-1);
  for (int i = (0); i < (n); i += (1))
    for (int j = (0); j < (m); j += (1)) {
      if (c[i][j] ^ '#') continue;
      c[i][j] = '.';
      ++vid;
      bool first = true;
      for (int x = (0); x < (n); x += (1))
        for (int y = (0); y < (m); y += (1)) {
          if (c[x][y] ^ '.' && visited[x][y] ^ vid) {
            if (first)
              dfs(x, y);
            else
              f(1);
            first = false;
          }
        }
      c[i][j] = '#';
    }
  f(2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Suhaib_Sawalha();
  return 0;
}
