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.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Hello {
  static int []fa = new int[10000];
  static int gf(int x) {
    //return (x==fa[x])?x:fa[x] = gf(fa[x]);
    if (x == fa[x]) {
      return x;
    } 
    fa[x] = gf(fa[x]);
    return fa[x];
  }

  public static void main(String[] args) {
    //try {
    //  FileInputStream fis = new FileInputStream("data.txt");
    //  System.setIn(fis);
      //Scanner in = new Scanner(System.in);
      FastReader in = new FastReader(System.in);
      
      
      int n = in.nextInt();
      int m = in.nextInt();
      //System.out.print("n:"+n);
      //System.out.print("m:"+m);
      char [][]mat = new char[n][m];
      int count = 0;
      for (int i = 0;i < n;++i) {
	String s = in.nextLine();
	//System.out.println(s);
	for (int j = 0;j < m;++j) {
	  mat[i][j] = s.charAt(j);
	  if (mat[i][j] == '#') count++;
	}
      }
      if (count <= 2) {
	System.out.println(-1);
	return;
      }
      for (int i = 0;i < n;++i) {
	for (int j = 0;j < m;++j) {
	  if (mat[i][j] != '#') continue;
	  mat[i][j] = '$';

	  for (int z = 0;z < m * n;++z) fa[z] = z;
	  
	  for (int r = 0;r < n;++r) {
	    for (int c = 0;c < m;++c) {
	      if (mat[r][c] != '#') continue;
	      if (c + 1 < m && mat[r][c + 1] == '#') {
		int id1 = r * m + c;
		int id2 = r * m + c + 1;
		fa[gf(id1)] = gf(id2);
	      }
	      if (r + 1 < n && mat[r + 1][c] == '#') {
		int id1 = r * m + c;
		int id2 = (1 + r) * m + c;
		fa[gf(id1)] = gf(id2);
	      }
	    }
	  }
	  int []sz = new int[n*m + 1];
	  for (int z = 0;z < n*m;++z) sz[z] = 0;
	  //for (int z = 0;z < n*m;++z) sz[gf(z)] += 1;

	  for (int r = 0;r < n;++r) {
	    for (int c = 0;c < m;++c) {
	      if (mat[r][c] != '#') continue;
	      int z = r * m + c;
	      sz[gf(z)] += 1;
	    }
	  }
	  int cnt = 0;
	  for (int z = 0;z < n*m;++z) {
	    if (sz[z] != 0) cnt += 1;
	  }
	  if (cnt > 1) {
	    System.out.println(1);

	    //for (int r = 0;r < n;++r) {
	    //  for (int c = 0;c < m;++c) {
	    //    System.out.print(mat[r][c]);
	    //  }
	    //  System.out.println();
	    //}
	    return;
	  }
	  mat[i][j] = '#';
	}
      }
      System.out.println(2);



	  

      
      




      
    //} catch (FileNotFoundException e){
    //  System.out.println("error");
    //}
  }
}

class FastReader {
    private boolean finished = false;
 
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;
 
    public FastReader(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 int peek() {
        if (numChars == -1) {
            return -1;
        }
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                return -1;
            }
            if (numChars <= 0) {
                return -1;
            }
        }
        return buf[curChar];
    }
 
    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 == ',') {
                c = read();
            }
            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 String nextString() {
        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 isWhitespace(c);
    }
 
    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
 
    private String readLine0() {
        StringBuilder buf = new StringBuilder();
        int c = read();
        while (c != '\n' && c != -1) {
            if (c != '\r') {
                buf.appendCodePoint(c);
            }
            c = read();
        }
        return buf.toString();
    }
 
    public String nextLine() {
        String s = readLine0();
        while (s.trim().length() == 0)
            s = readLine0();
        return s;
    }
 
    public String nextLine(boolean ignoreEmptyLines) {
        if (ignoreEmptyLines) {
            return nextLine();
        } else {
            return readLine0();
        }
    }
 
    public BigInteger nextBigInteger() {
        try {
            return new BigInteger(nextString());
        } catch (NumberFormatException e) {
            throw new InputMismatchException();
        }
    }
 
    public char nextCharacter() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        return (char) c;
    }
 
    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 boolean isExhausted() {
        int value;
        while (isSpaceChar(value = peek()) && value != -1)
            read();
        return value == -1;
    }
 
    public String next() {
        return nextString();
    }
 
    public SpaceCharFilter getFilter() {
        return filter;
    }
 
    public void setFilter(SpaceCharFilter filter) {
        this.filter = filter;
    }
 
    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}
