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>
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Saransh
 */
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {

    /**
     * @param args the command line arguments
     */
    static int r, c;
    static char[][] arr;
    static boolean[][] marked;
    static boolean[][] marker;
    public static void main(String[] args) {
        // TODO code application logic here
        try {
            Parserdoubt pd = new Parserdoubt(System.in);
            r = pd.nextInt();
            c = pd.nextInt();
            arr = new char[r][c];
            char [][]tmp = new char[r][c];
            marked = new boolean[r][c];
            int counter=0;
            for (int i = 0; i < r; i++) {
                arr[i] = pd.nextString().toCharArray();
                for(int j=0;j<c;j++)
                {
                    tmp[i][j] = arr[i][j];
                    if(tmp[i][j]=='#')counter++;
                }
            }
marked = new boolean[r][c];
marker=new boolean[r][c];
            int res=5;
            for(int i=0;i<r;i++)
            {
                for(int j=0;j<c;j++)
                {
                    if(arr[i][j]=='.')continue;
                    for(int k=0;k<16;k++)
                    {
                        if(Integer.bitCount(k)>=res)continue;
                        
                        
                        if((k&1)>0&&(i+1)<r)
                        {
                            marker[i+1][j]=true;
                        }
                        if((k&2)>0&&(j+1)<c)
                        {
                            marker[i][j+1]=true;
                        }
                        if((k&4)>0&&i-1>-1)
                        {
                            marker[i-1][j]=true;
                        }
                        if((k&8)>0&&j-1>-1)
                        {
                            marker[i][j-1]=true;
                        }
                        dfs(i,j);
                        if((k&1)>0&&(i+1)<r)
                        {
                            marker[i+1][j]=false;
                        }
                        if((k&2)>0&&(j+1)<c)
                        {
                            marker[i][j+1]=false;
                        }
                        if((k&4)>0&&i-1>-1)
                        {
                            marker[i-1][j]=false;
                        }
                        if((k&8)>0&&j-1>-1)
                        {
                            marker[i][j-1]=false;
                        }
                        int counter1=0;
                        for(int i1=0;i1<r;i1++)
                            for(int j1=0;j1<c;j1++)
                                if(marked[i1][j1])
                                {
                                    counter1++;
                                    marked[i1][j1]=false;
                                }
                        if(counter1<counter-Integer.bitCount(k))
                        {
                            res=Math.min(res,Integer.bitCount(k));
                        }
                    }
                }
            }
            if(res!=5)
                System.out.println(res);
            else
                System.out.println(-1);
            

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void dfs(int x, int y) {
        if (x >= r || y >= c) {
            return;
        }
        if (x < 0 || y < 0) {
            return;
        }
        if (arr[x][y] == '.') {
            return;
        }
        if (marked[x][y]||marker[x][y]) {
            return;
        }
        marked[x][y] = true;
        //System.out.println(x+" "+y+" "+sx+" "+sy);


        dfs(x + 1, y);
        dfs(x, y - 1);
        dfs(x - 1, y);
        dfs(x, 1 + y);


    }
    static int check(int a,int b)
    {
        if(a>=0&&a<arr.length&&b>=0&&b<arr[0].length)
        {
            if(arr[a][b]=='#')
                return 1;
            return 0;
        }
        return 0;
    }

    private static int deg(int i, int j) {
        return check(i+1,j)+check(i-1,j)+check(i,j+1)+check(i,j-1);
    }
}

class Parserdoubt {

    final private int BUFFER_SIZE = 1 << 17;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Parserdoubt(InputStream in) {
        din = new DataInputStream(in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String nextString() throws Exception {
        StringBuffer sb = new StringBuffer("");
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        do {
            sb.append((char) c);
            c = read();
        } while (c > ' ');
        return sb.toString();
    }

    public char nextChar() throws Exception {
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        return (char) c;
    }

    public int nextInt() throws Exception {
        int ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    public long nextLong() throws Exception {
        long ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    private void fillBuffer() throws Exception {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) {
            buffer[0] = -1;
        }
    }

    private byte read() throws Exception {
        if (bufferPointer == bytesRead) {
            fillBuffer();
        }
        return buffer[bufferPointer++];
    }
}
