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>
/*input
1 10
.########.

*/
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	static PrintWriter out;
	static int MOD = 1000000007;
	static FastReader scan;

    /*-------- I/O using short named function ---------*/
	public static String ns(){return scan.next();}
	public static int ni(){return scan.nextInt();}
	public static long nl(){return scan.nextLong();}
	public static double nd(){return scan.nextDouble();}
	public static String nln(){return scan.nextLine();}
	public static void p(Object o){out.print(o);}
	public static void ps(Object o){out.print(o + " ");}
	public static void pn(Object o){out.println(o);}
    /*-------- for output of an array ---------------------*/
     static void iPA(int arr []){
     	 StringBuilder output = new StringBuilder();
	     for(int i=0; i<arr.length; i++)output.append(arr[i] + " ");out.println(output);
	}
	static void lPA(long arr []){
	     StringBuilder output = new StringBuilder();
	     for(int i=0; i<arr.length; i++)output.append(arr[i] + " ");out.println(output);
	}
	static void sPA(String arr []){
	     StringBuilder output = new StringBuilder();
	     for(int i=0; i<arr.length; i++)output.append(arr[i] + " ");out.println(output);
	}
	static void dPA(double arr []){
	     StringBuilder output = new StringBuilder();
	     for(int i=0; i<arr.length; i++)output.append(arr[i] + " ");out.println(output);
	}
    /*-------------- for input in an array ---------------------*/
	static void iIA(int arr[]){
	     for(int i=0; i<arr.length; i++)arr[i] = ni();
	}
	static void lIA(long arr[]){
	     for(int i=0; i<arr.length; i++)arr[i] = nl(); 
	}
	static void sIA(String arr[]){
	     for(int i=0; i<arr.length; i++)arr[i] = ns(); 
	}
	static void dIA(double arr[]){
	     for(int i=0; i<arr.length; i++)arr[i] = nd();
	}
	/*------------ for taking input faster ----------------*/
     static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}

	// Method to check if x is power of 2
    static boolean isPowerOfTwo (int x) { return x!=0 && ((x&(x-1)) == 0);}
    //Method to return lcm of two numbers
    static int gcd(int a, int b){return a==0?b:gcd(b % a, a); }
    //Method to count digit of a number
    static int countDigit(long n){return (int)Math.floor(Math.log10(n) + 1);}

    //Method for sorting
	static void ruffle_sort(int[] a) {
		//shandom_ruffle
		Random r=new Random();
		int n=a.length;
		for (int i=0; i<n; i++) {
			int oi=r.nextInt(n);
			int temp=a[i];
			a[i]=a[oi];
			a[oi]=temp;
		}
		//sort
		Arrays.sort(a);
	}
	//Method for checking if a number is prime or not
	static boolean isPrime(int n) { 
        if (n <= 1) return false; 
        if (n <= 3) return true; 
        if (n % 2 == 0 || n % 3 == 0) return false; 
        for (int i = 5; i * i <= n; i = i + 6) 
            if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
        return true; 
    } 
    static int n, m;
	public static void main (String[] args) throws java.lang.Exception
	{
		OutputStream outputStream =System.out;
        out =new PrintWriter(outputStream);
        scan =new FastReader();
		//for fast output sometimes
		StringBuilder sb = new StringBuilder();
		n = ni(); m = ni();
		char ch[][] = new char[n][m];
		for(int i=0; i<n; i++){
			String s = ns();
			ch[i] = s.toCharArray();
		}
		
		int X=0, Y=0, xLast=0, yLast=0;
		boolean found = false;
		int count=0;
		for(int i=0; i<n; i++){
			for(int j=0;j<m; j++){
				if(ch[i][j] == '#'){
					count++;
					if(!found){
						X = i; Y = j;
						found = true;
					}
					xLast = i; yLast = j;
				}
			}
		}
		if(count<=2){
			pn(-1);
			out.flush();
			out.close();
			return;
		}
		boolean oneFound = false;
		for(int i=0; i<n; i++){
			for(int j=0; j<m; j++){
				if(ch[i][j] == '#'){
					ch[i][j] = '.';
					boolean visited[][] = new boolean[n][m];
					//pn(i + " " + j);
					//pn(xLast + " " + yLast);
					if(i==X && j==Y){
						dfs(ch, xLast, yLast, visited);
					}
					else
						dfs(ch, X, Y, visited);
					//pn(" ================ " + i + "  " + j);
					for(int a=0; a<n; a++){
						for(int b=0; b<m; b++){
							int connected = 1;

							if(ch[a][b]=='#' && !visited[a][b]){
								dfs(ch, a, b, visited);
								connected++;
							}
							if(connected>1){
								oneFound = true;
								break;
							}
						}
					}
					ch[i][j] = '#';
				}
				if(oneFound)
					break;
			}
			if(oneFound)
				break;
		}
		if(oneFound)
			pn(1);
		else
			pn(2);
        out.flush();
		out.close();
	}
	static int move[][] = new int[][]{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
	static boolean isSafe(int x, int y){
		return x>=0 && x<n && y>=0 && y<m; 
	}
	static void dfs(char ch[][], int sx, int sy, boolean visited[][]){
		//pn("---- " + sx + " " + sy);
		visited[sx][sy] = true;
		for(int i=0; i<move.length; i++){
			int x = move[i][0];
			int y = move[i][1];
			x += sx;
			y += sy;
			if ( isSafe(x, y) && !visited[x][y] && ch[x][y]=='#') {
				dfs(ch, x, y, visited);
			}
		}
	}
}