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

public class ranjan{

    public static Read cin;
    //public static InputReader cin;
    public static PrintWriter cout;
    public static boolean[] safe;
	public static boolean[][] visited;
    public static final long bil = (long)1e9+7;
    public static int fileread = 0; 
    
    public static void main(String ...arg) throws IOException
    {
        /*console writer*/
        cout = new PrintWriter(new BufferedOutputStream(System.out));
        /*Debug Reader*/
        //Scan cin =new Scan();
        if(fileread == 1)
        {
            try
            {
            cin = new Read(new FileInputStream(new File("in1.txt")));
            //cin = new InputReader(new FileInputStream(new File("in2.txt")));
            }
            catch (IOException error){}
        }
        else{
            cin = new Read(System.in);
            //cin = new InputReader(System.in);
        }
		//input
		int n = cin.nextInt();
		int m = cin.nextInt();
		char[][] mat = new char[n][m];
		visited = new boolean[n][m];
		for(int i=0;i<n;i++) mat[i] = cin.nextLine().toCharArray();
			
		int[] dir = new int[]{-1,0,1,0,-1};
		int painted = 0,ans = 2;
		//dfs
		for(int i=0;i<n;i++)
			for(int j=0;j<m;j++)
				{
					if(mat[i][j] == '#')
					{
						painted++;
						mat[i][j] = '.';
						for(boolean[] x:visited) Arrays.fill(x,false);
						int region = 0;
						for(int k=0;k<4;k++)
							region += dfs(mat,dir,i+dir[k],j+dir[k+1]);
						if(region>1)
							ans = 1;
						mat[i][j] = '#';
					}
				}
		cout.print(painted<3?-1:ans);
		cout.close();
    }

	public static int dfs(char[][] mat,int[] dir,int x,int y)
	{
		if(x<0 || y<0 || x>=mat.length || y>=mat[0].length || visited[x][y] || mat[x][y]=='.')
			return 0;
		visited[x][y] = true;
		for(int i=0;i<4;i++)
			dfs(mat,dir,x+dir[i],y+dir[i+1]);
		return 1;
	}

	private static class Pair{
		public int a,b;
		public Pair(int a,int b)
		{
			this.a = a;
			this.b = b;
		}	
	}


    /*public static void seive(int size)
    {
        prime[0] = prime[1] = false;
        int p = 2;
        while(p*p<= size)
        {
            if(prime[p])
            {
                for(int i=p*p;i<size;i += p)
                    prime[i] = false;
            }
            p++;
        }
    }*/


    public static <K, V> V getOrDefault(HashMap<K,V> map, K key, V defaultValue) {
        return map.containsKey(key) ? map.get(key) : defaultValue;
    }
    
    static void reverseArray(int intArray[], int size) 
    { 
        int i, temp; 
        for (i = 0; i < size / 2; i++) { 
            temp = intArray[i]; 
            intArray[i] = intArray[size - i - 1]; 
            intArray[size - i - 1] = temp; 
        }  
    } 

    public static long mod_pow(long x,long n,long mod) {
        long res=1;
        while(n>0) {
            if((n&1)==1)res=res*x%mod;
            x=x*x%mod;
            n>>=1;
        }
        return res;
    }
    public static int gcd(int n1, int n2) 
    {
        int r;
        while (n2 != 0) 
        {
            r = n1 % n2;
            n1 = n2;
            n2 = r;
        }
        return n1;
    }
 
    /*public static int lcm(int n1, int n2) 
    {
        int answer = (n1 * n2) / (gcd(n1, n2));
        return answer;
    }*/


    static class InputReader {
        final InputStream is;
        final byte[] buf = new byte[1024];
        int pos;
        int size;
 
        public InputReader(InputStream is) {
            this.is = is;
        }
 
        public int nextInt() {
            int c = read();
            while (isWhitespace(c))
                c = read();
            int sign = 1;
            if (c == '-') {
                sign = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res = res * 10 + c - '0';
                c = read();
            } while (!isWhitespace(c));
            return res * sign;
        }
 
        int read() {
            if (size == -1)
                throw new InputMismatchException();
            if (pos >= size) {
                pos = 0;
                try {
                    size = is.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (size <= 0)
                    return -1;
            }
            return buf[pos++] & 255;
        }
 
        static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
 
    }

static class RecursionLimiter {
    public static long maxLevel = 100000L;

    public static void emerge() {
        if (maxLevel == 0)
            return;
        try {
            throw new IllegalStateException("Too deep, emerging");
        } catch (IllegalStateException e) {
            if (e.getStackTrace().length > maxLevel + 1)
                throw e;
        }
    }
}


static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }

}

class Read
{
    private BufferedReader br;
    private StringTokenizer st;

    public Read(InputStream is)
    { br = new BufferedReader(new InputStreamReader(is)); }

    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            try {st = new StringTokenizer(br.readLine());}
            catch(IOException e)
                {e.printStackTrace();}
        }
        return st.nextToken();
    }

    int nextInt()
    { return Integer.parseInt(next()); }

    long nextLong()
    { return Long.parseLong(next()); }

    double nextDouble()
    { return Double.parseDouble(next()); }

    String nextLine()
    {
        String str = "";
        try {str = br.readLine();}
        catch(IOException e)
            {e.printStackTrace();}
        return str;
    }
}

