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.*;

/* spar5h */

public class swagdaddy implements Runnable { 
	 
	static class pair{
		
		int i, j;
		
		pair(int i, int j) {
			this.i = i; this.j = j;
		}
	}
	
	static ArrayList<pair>[][] adj;
	static char[][] a;
	static pair[][] parent;
	static int[][] vis, low, disc, res;
	static int count;
	
	static void DFS(int xi, int xj) {
		
		vis[xi][xj] = 1;
		low[xi][xj] = disc[xi][xj] = count++;
		int subCount = 0;
		
		for(int i = 0; i < adj[xi][xj].size(); i++) {
			
			int yi = adj[xi][xj].get(i).i;
			int yj = adj[xi][xj].get(i).j;
			
			if(vis[yi][yj] == 0) {
				
				subCount++;
				parent[yi][yj] = new pair(xi, xj);
				
				DFS(yi, yj);
				
				low[xi][xj] = Math.min(low[xi][xj], low[yi][yj]);
				
				if(!(parent[xi][xj].i == 0 && parent[xi][xj].j == 0) && low[xi][xj] >= disc[xi][xj])
					res[xi][xj] = 1;
			}
			
			else if(!(parent[xi][xj].i == yi && parent[xi][xj].j == yj))
				low[xi][xj] = Math.min(low[xi][xj], disc[yi][yj]);
		}
		
		if(parent[xi][xj].i == 0 && parent[xi][xj].j == 0 && subCount > 1)
			res[xi][xj] = 1;	
		
		//System.out.println(xi + " " + xj);
		//System.out.println(disc[xi][xj] + " " + low[xi][xj] + " " + res[xi][xj]);
	}
	
	public void run() {

		InputReader s = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

		int t = 1;
		
		while(t-- > 0) {
			
			int n = s.nextInt();
			int m = s.nextInt();
			
			int areaCount = 0;
			int si = -1, sj = -1;
			
			a = new char[n + 1][m + 1];
			
			for(int i = 1; i <= n; i++)
				a[i] = (" " + s.next()).toCharArray();
			
			adj = new ArrayList[n + 1][m + 1];
			
			for(int i = 1; i <= n; i++) {
				
				for(int j = 1; j <= m; j++) {
					
					if(a[i][j] == '.')
						continue;
					
					adj[i][j] = new ArrayList<pair>();
					
					if(j - 1 >= 1 && a[i][j - 1] == '#')
						adj[i][j].add(new pair(i, j - 1));
					
					if(j + 1 <= m && a[i][j + 1] == '#')
						adj[i][j].add(new pair(i, j + 1));
					
					if(i - 1 >= 1 && a[i - 1][j] == '#')
						adj[i][j].add(new pair(i - 1, j));
					
					if(i + 1 <= n && a[i + 1][j] == '#')
						adj[i][j].add(new pair(i + 1, j));
					
					areaCount++;
					si = i; sj = j;
				}
			}
			
			if(areaCount <= 2) {
				w.println(-1); continue;
			}
			
			vis = new int[n + 1][m + 1];
			parent = new pair[n + 1][m + 1];
			low = new int[n + 1][m + 1];
			disc = new int[n + 1][m + 1];
			res = new int[n + 1][m + 1];
			count = 1;
			
			parent[si][sj] = new pair(0, 0);
			DFS(si, sj);
			
			int ans = 2;
			
			for(int i = 1; i <= n; i++)
				for(int j = 1; j <= m; j++)
					if(res[i][j] == 1)
						ans = 1;
			
			w.println(ans);
			
		}
		
		w.close();
	}
	
	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		
		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}
		
		public int read()
		{
			if (numChars==-1) 
				throw new InputMismatchException();
			
			if (curChar >= numChars)
			{
				curChar = 0;
				try 
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}
				
				if(numChars <= 0)				
					return -1;
			}
			return buf[curChar++];
		}
	 
		public String nextLine()
		{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
		}
		public int nextInt()
		{
			int c = read();
			
			while(isSpaceChar(c)) 
				c = read();
			
			int sgn = 1;
			
			if (c == '-') 
			{
				sgn = -1;
				c = read();
			}
			
			int res = 0;
			do 
			{
				if(c<'0'||c>'9') 
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c)); 
			
			return res * sgn;
		}
		
		public long nextLong() 
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') 
			{
				sgn = -1;
				c = read();
			}
			long res = 0;
			
			do 
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));
				return res * sgn;
		}
		
		public double nextDouble() 
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') 
			{
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') 
			{
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') 
			{
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) 
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}
		
		public String readString() 
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do 
			{
				res.appendCodePoint(c);
				c = read();
			} 
			while (!isSpaceChar(c));
			
			return res.toString();
		}
	 
		public boolean isSpaceChar(int c) 
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	 
		public String next() 
		{
			return readString();
		}
		
		public interface SpaceCharFilter 
		{
			public boolean isSpaceChar(int ch);
		}
	}
    
	public static void main(String args[]) throws Exception
	{
		new Thread(null, new swagdaddy(),"swagdaddy",1<<26).start();
	}
	   
} 