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>
import java.util.*;
import java.io.*;

public class Main implements Runnable {
	private void dfs(int i, int j){
                was[i][j] = true;
                for(int k = 0; k < 4; k++){
                        int ni = i + dx[k];
                        int nj = j + dy[k];
                        
                        if(ni >= 0 && ni < N && nj >= 0 && nj < M){
                                if(graph[ni][nj] == '#' && !was[ni][nj]){
                                        dfs(ni, nj);
                                }
                        }
                }
                
                
        }	
        
        int N;
        int M;
        boolean[][] was;
        char[][] graph;
        int[] dx = {1, -1, 0, 0};
        int[] dy = {0, 0, -1, 1};
        
	public void solve() throws IOException {
		N = nextInt();
                M = nextInt();
                graph = new char[N][M];
                was = new boolean[N][M];
                for(int i = 0; i < N; i++){
                        graph[i] = nextToken().toCharArray();
                }
                
                int size = 0;
                        for(int i = 0; i < N ;i++)
                                for(int j =0 ; j < M; j++)
                                        if(graph[i][j] == '#')
                                                size++;
                        
                if(size <= 2){
                        System.out.println(-1);
                        return;
                }
                //if it is a line, then 1 cut is enough to make 2 splits
                //if a cirlce is formed we have to make 2 cuts
                //if 2 circles intersect at one  point , 1 cut is enough in between
                //cut a node, check if  2 segements are formed if YES print 1
                //else in the end print 2

                for(int i = 0; i < N ; i++){
                        for(int j = 0; j < M; j++){
                                if(graph[i][j] == '#'){
                                        graph[i][j] = '.'; //remove the node
                                        
                                        for(int k = 0; k < N; k++) Arrays.fill(was[k], false);
                                        int sx = -1, sy = -1;
                                        for(int ii = 0; ii < N; ii++)
                                                for(int jj = 0; jj < M; jj++)
                                                        if(graph[ii][jj] == '#'){
                                                                sx = ii;
                                                                sy = jj;
                                                        }
                                       
                                        dfs(sx, sy);
                                        
                                        boolean twoLines = false;
                                        for(int ii = 0; ii < N; ii++)
                                                for(int jj = 0; jj < M; jj++)
                                                        if(graph[ii][jj] == '#' && !was[ii][jj]) //this point is separated from the other
                                                                twoLines = true;
                                        
                                        if(twoLines){
                                                System.out.println(1);
                                                return;
                                        }
                                        
                                        graph[i][j] = '#'; // add the node back
                                }
                        }
                }
                
                
               //it seems 1 node deletion have failed, print 2
                System.out.println(2);
        
        }

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }
        
        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }
        
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	BufferedReader in;
	StringTokenizer tok;
}