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

public class Main {

	static class FastScanner {
		BufferedReader s;
		StringTokenizer st;

		public FastScanner(InputStream InputStream) {
			st = new StringTokenizer("");
			s = new BufferedReader(new InputStreamReader(InputStream));
		}

		public FastScanner(File f) throws FileNotFoundException {
			st = new StringTokenizer("");
			s = new BufferedReader(new FileReader(f));
		}

		public int nextInt() throws IOException {
			if (st.hasMoreTokens())
				return Integer.parseInt(st.nextToken());
			else {
				st = new StringTokenizer(s.readLine());
				return nextInt();
			}
		}

		public BigInteger big() throws IOException {
			if (st.hasMoreTokens())
				return new BigInteger(st.nextToken());
			else {
				st = new StringTokenizer(s.readLine());
				return big();
			}
		}

		public double nextDouble() throws IOException {
			if (st.hasMoreTokens())
				return Double.parseDouble(st.nextToken());
			else {
				st = new StringTokenizer(s.readLine());
				return nextDouble();
			}
		}

		public long nextLong() throws IOException {
			if (st.hasMoreTokens())
				return Long.parseLong(st.nextToken());
			else {
				st = new StringTokenizer(s.readLine());
				return nextLong();
			}
		}

		public String next() throws IOException {
			if (st.hasMoreTokens())
				return st.nextToken();
			else {
				st = new StringTokenizer(s.readLine());
				return next();
			}

		}

		public String nextLine() throws IOException {
			return s.readLine();
		}

		public void close() throws IOException {
			s.close();
		}

	}

	public static void main(String[] args) throws IOException {
		FastScanner in = new FastScanner(System.in);
		int n = in.nextInt(), m = in.nextInt();
		String arr[] = new String[n];
		for(int x = 0; x < n; x++) 
			arr[x] = in.next();
		int num = 0;
		int i = 0, j = 0;
		for(int x = 0; x < n; x++) {
			for(int y = 0; y < m; y++) {
				if(arr[x].charAt(y) == '#') {
					num++;
					i = x;
					j = y;
				}
			}
		}
		if(num <= 2) {
			System.out.println(-1);
			return;
		}
		boolean flag = false;
		boolean[][] vis = new boolean[n][m];
		vis[i][j] = true;
		if(i > 0 && arr[i - 1].charAt(j) == '#') {
			if(dfs(arr, i - 1, j, vis, new int[n][m], new int[n][m], 1)) {
				flag = true;
			}
		}
		else if(j > 0 && arr[i].charAt(j - 1) == '#')  {
			if(dfs(arr, i, j - 1, vis, new int[n][m], new int[n][m], 1)) {
				flag = true;
			}
		}
		else if(i < n - 1 && arr[i + 1].charAt(j) == '#') {
			if(dfs(arr, i + 1, j, vis, new int[n][m], new int[n][m], 1)) {
				flag = true;
			}
		}
		else if(j < m - 1 && arr[i].charAt(j + 1) == '#') {
			if(dfs(arr, i, j + 1, vis, new int[n][m], new int[n][m], 1)) {
				flag = true;
			}
		}
		if(!flag) {
			if(i > 0 && !vis[i - 1][j] && arr[i - 1].charAt(j) == '#') {
				flag = true;
			}
			else if(j > 0 && !vis[i][j - 1] && arr[i].charAt(j - 1) == '#') {
				flag = true;
			}
			else if(i < n - 1 && !vis[i + 1][j] && arr[i + 1].charAt(j) == '#') {
				flag = true;
			}
			else if(j < m - 1 && ! vis[i][j + 1] && arr[i].charAt(j + 1) == '#') {
				flag = true;
			}
		}
		if(flag)
			System.out.println(1);
		else
			System.out.println(2);
	}

	private static boolean dfs(String[] arr, int x, int y, boolean[][] vis, int[][] dis, int[][] low, int i) {
		vis[x][y] = true;
		dis[x][y] = i;
		low[x][y] = i;
		if(x > 0 && arr[x - 1].charAt(y) == '#')
			if(!vis[x - 1][y]){
				if(dfs(arr, x - 1, y, vis, dis, low, i + 1)) {
					return true;
				}
				else {
					if(low[x - 1][y] >= i)
						return true;
					else
						low[x][y] = Math.min(low[x][y], low[x - 1][y]);
				}
			}
			else {
				low[x][y] = Math.min(low[x][y], dis[x - 1][y]);
			}
		if(y > 0 && arr[x].charAt(y - 1) == '#')
			if(!vis[x][y - 1]){
				if(dfs(arr, x, y - 1, vis, dis, low, i + 1)) {
					return true;
				}
				else {
					if(low[x][y - 1] >= i)
						return true;
					else
						low[x][y] = Math.min(low[x][y], low[x][y - 1]);
				}
			}
			else {
				low[x][y] = Math.min(low[x][y], dis[x][y - 1]);
			}
		if(x < arr.length - 1 && arr[x + 1].charAt(y) == '#')
			if(!vis[x + 1][y]){
				if(dfs(arr, x + 1, y, vis, dis, low, i + 1)) {
					return true;
				}
				else {
					if(low[x + 1][y] >= i)
						return true;
					else
						low[x][y] = Math.min(low[x][y], low[x + 1][y]);
				}
			}
			else {
				low[x][y] = Math.min(low[x][y], dis[x + 1][y]);
			}
		if(y < arr[0].length() - 1 && arr[x].charAt(y + 1) == '#')
			if(!vis[x][y + 1]){
				if(dfs(arr, x, y + 1, vis, dis, low, i + 1)) {
					return true;
				}
				else {
					if(low[x][y + 1] >= i)
						return true;
					else
						low[x][y] = Math.min(low[x][y], low[x][y + 1]);
				}
			}
			else {
				low[x][y] = Math.min(low[x][y], dis[x][y + 1]);
			}
		return false;
	}
}