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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nafiur Rahman Khadem Shafin 🙂
 */
public class Main {
	public static void main (String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader (inputStream);
		PrintWriter out = new PrintWriter (outputStream);
		TaskA solver = new TaskA ();
		solver.solve (1, in, out);
		out.close ();
	}
	
	static class TaskA {
		private char[][] arr;
		private int n;
		private int m;
		private int time;
		private final byte[] da = {1, 0, 0, -1};
		private final byte[] db = {0, 1, -1, 0};
		private int[][] discover;
		private int[][] low;
		
		private boolean dfs2dIsArticulation (int a, int b, int pa, int pb) {
			int cntChildren = 0;
			discover[a][b] = low[a][b] = ++time;
			for (int i = 0; i<4; i++) {
				int ra = a+da[i], rb = b+db[i];
				if (ra >= 0 && ra<n && rb >= 0 && rb<m && arr[ra][rb]=='#') {
					if (discover[ra][rb]==0) {
						if (dfs2dIsArticulation (ra, rb, a, b)) {
							return true;
						}
						low[a][b] = Math.min (low[a][b], low[ra][rb]);
						if (pa==-1 && pb==-1) {
							cntChildren++;
							if (cntChildren>1) {
								return true;
							}
						}
						else if (low[ra][rb] >= discover[a][b]) {
							return true;
						}
					}
					else if (ra!=pa || rb!=pb) {//as articulation is done only on directed graph so every node has a
						// backedge to its parent, but we must ignore it otherwise every low will be 0, here it can also be
						// crossedge instead of backedge so low already might have been updated unlike SCC
						low[a][b] = Math.min (low[a][b], discover[ra][rb]);
					}
				}
			}
			return false;
		}
		
		public void solve (int testNumber, InputReader in, PrintWriter out) {
			/*
			 * observation: ansewr can be only 1, 2, -1. If number of vertices is <=2 answer is -1. M.W. corner case here:
			 * no vertex.
			 * If there is any articulation point then it's 1, else answer is 2.
			 */
			n = in.nextInt ();
			m = in.nextInt ();
			arr = new char[n+5][];
			discover = new int[n+5][m+5];
			low = new int[n+5][m+5];
			for (int i = 0; i<n; i++) {
				arr[i] = in.next ().toCharArray ();
			}
			time = 0;
			int cntHash = 0;
			for (int i = 0; i<n; i++) {
				for (int j = 0; j<m; j++) {
					if (arr[i][j]=='#') {
						if (discover[i][j]==0 && dfs2dIsArticulation (i, j, -1, -1)) {
							out.println (1);
							return;
						}
						cntHash++;
					}
				}
			}
			if (cntHash<=2) {
				out.println (-1);
			}
			else {
				out.println (2);
			}
		}
		
	}
	
	static class InputReader implements AutoCloseable {
		private BufferedReader reader;
		private StringTokenizer tokenizer;
		
		public InputReader (InputStream stream) {
			reader = new BufferedReader (new InputStreamReader (stream));
			tokenizer = null;
		}
		
		public String next () {
			while (tokenizer==null || !tokenizer.hasMoreTokens ()) {
				try {
					String str;
					if ((str = reader.readLine ())!=null) tokenizer = new StringTokenizer (str);
					else return null;//to detect eof
				} catch (IOException e) {
					throw new RuntimeException (e);
				}
			}
			return tokenizer.nextToken ();
		}
		
		public int nextInt () {
			return Integer.parseInt (next ());
		}
		
		
		public void close () throws Exception {
			reader.close ();
		}
		
	}
}

