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>
/*

I FOLLOW THE WAY OF THE RIGHT HONOURABLE JIM KWIK,
GOD BLESS YOU SIR

1.  I AM A 'NEWBIE' IN RATING
2.  I WILL FAIL MANY TIMES, BUT I WILL NOT FAIL TO LEARN FROM FAILURE
3.  I WILL NEVER SURRENDER MY GOAL, NO MATTER HOW MUCH I FAIL
4.  I WILL PROVE MY SKILLS WHEN THE TIME COMES


*/





import java.util.*;
import java.io.*;
public class A {














    static boolean tests = false;
    static int n, m;
    static boolean[][] vis, grid;
    static void flood(int i, int j){
        vis[i][j] = true;
         if (i > 0 && !vis[i-1][j] && grid[i-1][j])
             flood(i-1, j);
         if (i < n-1 && !vis[i+1][j] && grid[i+1][j])
             flood(i+1, j);
         if (j > 0 && !vis[i][j-1] && grid[i][j-1])
             flood(i, j-1);
         if (j < m-1 && !vis[i][j+1] && grid[i][j+1])
             flood(i, j+1);
    }
    static int components(){
        int cnt = 0;
        vis = new boolean[n][m];
        for (int i = 0; i < n; ++i){
            for (int j = 0; j < m; ++j){
                if (vis[i][j] || !grid[i][j]) continue;
                flood(i, j);
                ++cnt;
            }
        }
        return cnt;
    }
    static void solve(){
       n = fs.nextInt();
       m = fs.nextInt();
       grid = new boolean[n][m];
       int sz = 0;
       for (int i = 0; i < n; ++i){
           char[] line = fs.next().toCharArray();
           for (int j = 0; j < m; ++j) if (line[j] == '#'){
               grid[i][j] = true;
               ++sz;
           }
       }
       if (sz < 3){
           out.println(-1);
           return;
       }
       for (int i = 0; i < n; ++i){
           for (int j = 0; j < m; ++j){
               if (!grid[i][j]) continue;
               grid[i][j] = false;
               if (components() > 1){
                   out.println(1);
                   return;
               }
               grid[i][j] = true;
           }
       }
       out.println(2);
    }





















    static FastScanner fs;
    static PrintWriter out;
    static int int_max = (int)1e9, mod = int_max+7;
    public static void main(String[] args) {
        fs = new FastScanner();
        out = new PrintWriter(System.out);
        int t = 1;
        if (tests) t = fs.nextInt();
        while (t-- > 0) solve();
        out.close();
    }
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readIntArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long[] readLongArray(int n){
            long a[] = new long[n];
            for (int i = 0; i < n; ++i){
                a[i] = nextLong();
            }
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}