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

import static java.lang.Math.*;

public class Code implements Runnable {

    public static void main(String[] args) throws IOException {
        new Thread(new Code()).start();
    }

    boolean[][] used;
    int[][] delta = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };

    int dfs(int x, int y, StringBuilder[] sheet) {
        used[x][y] = true;
        int counter = 1;
        for(int i = 0; i < 4; ++i) {
            int xto = x + delta[i][0], yto = y + delta[i][1];
            if(xto < 0 || yto < 0 || xto >= sheet.length || yto >= sheet[x].length())   continue;
            if(sheet[xto].charAt(yto) == '#' && !used[xto][yto])    counter += dfs(xto, yto, sheet);
        }
        return counter;
    }

    private void solve() throws IOException {
        int n = nextInt(), m = nextInt();

        int counter = 0;
        StringBuilder[] sheet = new StringBuilder[n];
        boolean [][] graph = new boolean[max(n, m)][max(n, m)];
        for(int i = 0; i < n; ++i) {
            sheet[i] = new StringBuilder(nextToken());
            for(int j = 0; j < m; ++j) {
                if(sheet[i].charAt(j) == '#') {
                    ++counter;
                }
            }
        }

        if(counter == 3)    writer.println(1);
        else if(counter < 3)    writer.println(-1);
        else {
            used = new boolean[n][m];
            for(int i = 0; i < n; ++i) {
                for(int j = 0; j < m; ++j) {
                    if(sheet[i].charAt(j) == '#') {
                        sheet[i].setCharAt(j, '.');
                        int x = 0, y = 0;
                        for(int k = 0; k < 4; ++k) {
                            x = i + delta[k][0];
                            y = j + delta[k][1];
                            if(x < 0 || y < 0 || x >= sheet.length || y >= sheet[i].length() || sheet[x].charAt(y) == '.')   continue;
                            break;
                        }
                        if(dfs(x, y, sheet) != counter - 1) {
                            writer.println(1);
                            return;
                        }
                        for(int k = 0; k < n; ++k)  Arrays.fill(used[k], false);
                        sheet[i].setCharAt(j, '#');
                    }
                }
            }
            writer.println(2);
        }
    }

    private class Pair<E extends Comparable, V extends Comparable> implements Comparable<Pair<E, V>> {
        public Pair(E first, V second) {
            this.first = first;
            this.second = second;
        }

        @Override
        public int compareTo(Pair<E, V> obj) {
            if(first == obj.first)  return second.compareTo(obj.second);
            return first.compareTo(obj.first);
        }

        @Override
        public boolean equals(Object obj) {
            Pair other = (Pair)obj;
            return first.equals(other.first) && second.equals(other.second);
        }

        public E first;
        public V second;
    }

    @Override
    public void run() {
        try {
            if(in.equals(""))   reader = new BufferedReader(new InputStreamReader(System.in));
            else    reader = new BufferedReader(new FileReader(in));

            if(out.equals(""))  writer = new PrintWriter(new OutputStreamWriter(System.out));
            else    writer = new PrintWriter(new FileWriter(out));
            solve();
        } catch(IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
                writer.close();
            } catch(IOException e) {
                e.printStackTrace();
            }
        }
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private float nextFloat() throws IOException {
        return Float.parseFloat(nextToken());
    }

    private String nextToken() throws IOException {
        while(st == null || !st.hasMoreTokens())    st = new StringTokenizer(reader.readLine());
        return st.nextToken();
    }

    private String in = "", out = "";
    private BufferedReader reader;
    private PrintWriter writer;
    private StringTokenizer st;
}