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

public class CF194C {
    public static void main(String[] args) {
        new CF194C().run();
    }

    public void run() {
        Scanner scanner = new Scanner(System.in);
        try {
            int n = scanner.nextInt();
            int m = scanner.nextInt();
            scanner.nextLine();

            int [][] map = new int[m][n];
            for (int i = 0; i < m; i++)
                for (int j = 0; j < n; j++)
                    map[i][j] = -1;
            int j = 0;
            Graph graph = new Graph();
            for (int y = 0; y < n; y++) {
                String line = scanner.nextLine();
                for (int x = 0; x < m; x++) {
                    if (line.charAt(x) == '#') {
                        map[x][y] = j;
                        graph.put(j, new ArrayList<Integer>());
                        if (x > 0 && map[x - 1][y] != -1) {
                            graph.get(map[x - 1][y]).add(j);
                            graph.get(j).add(map[x - 1][y]);
                        }
                        if (y > 0 && map[x][y - 1] != -1) {
                            graph.get(map[x][y - 1]).add(j);
                            graph.get(j).add(map[x][y - 1]);
                        }
                        j++;
                    }
                }
            }

            int toRemove;
            if (graph.size() <= 2)
                toRemove = -1;
            else {
                CutNodesAndBridges dfs = new CutNodesAndBridges(graph);
                dfs.search(graph.keySet().iterator().next());
                if (dfs.cutNodes.size() > 0)
                    toRemove = 1;
                else
                    toRemove = 2;
            }
            System.out.println(toRemove);
        }
        finally {
            scanner.close();
        }
    }

    public static class Graph extends HashMap<Integer, List<Integer>> {}
    public static class Edge {
        public int from;
        public int to;
        public Edge(int from, int to) { this.from = from; this.to = to; }
    }
    public static enum EdgeClass { Tree, Back }

    public static class DFS {
        protected Graph graph;
        protected boolean[] discovered;
        protected boolean[] processed;
        protected int[] parent;
        protected int[] entryTime;
        protected int[] exitTime;
        protected int time;
        protected boolean finished;

        public DFS(Graph graph) {
            this.graph = graph;
            int size = graph.size();
            discovered = new boolean[size];
            processed = new boolean[size];
            parent = new int[size];
            for (int i = 0; i < size; i++) parent[i] = -1;
            entryTime = new int[size];
            exitTime = new int[size];
        }

        public void search(int v) {
            if (finished) return;

            discovered[v] = true;
            entryTime[v] = ++time;
            processVertexEarly(v);

            for (int y : graph.get(v)) {
                if (!discovered[y]) {
                    parent[y] = v;
                    processEdge(v, y);
                    search(y);
                }
                else if (!processed[y]) // || graph.directed
                    processEdge(v, y);
            }

            processVertexLate(v);
            exitTime[v] = ++time;
            processed[v] = true;
        }

        protected void processVertexEarly(int v) {}
        protected void processEdge(int x, int y) {}
        protected void processVertexLate(int v) {}

        protected EdgeClass classifyEdge(int x, int y) {
            if (parent[y] == x)
                return EdgeClass.Tree;
            else //if (discovered[y] && !processed[y])
                return EdgeClass.Back;
            // add Forward and Cross for directed graphs
        }
    }

    public static class CutNodesAndBridges extends DFS {
        protected int[] reachableAncestor;
        protected int[] treeOutDegree;
        public List<Integer> cutNodes;
        public List<Edge> bridges;

        public CutNodesAndBridges(Graph graph) {
            super(graph);
            reachableAncestor = new int[graph.size()];
            treeOutDegree = new int[graph.size()];
            cutNodes = new ArrayList<Integer>();
            bridges = new ArrayList<Edge>();
        }

        protected void processVertexEarly(int v) {
            reachableAncestor[v] = v;
        }

        protected void processEdge(int x, int y) {
            EdgeClass edgeClass = classifyEdge(x, y);
            if (edgeClass == EdgeClass.Tree)
                treeOutDegree[x]++;
            else if (edgeClass == EdgeClass.Back && parent[x] != y)
                if (entryTime[y] < entryTime[reachableAncestor[x]])
                    reachableAncestor[x] = y;
        }

        protected void processVertexLate(int v) {
            if (parent[v] == -1) { // tree root
                if (treeOutDegree[v] > 1)
                    cutNodes.add(v);
                return;
            }

            boolean parentIsRoot = (parent[parent[v]] == -1);
            if (reachableAncestor[v] == parent[v] && !parentIsRoot) { // parent cut node
                cutNodes.add(parent[v]);
            }
            else if (reachableAncestor[v] == v) { // bridge
                cutNodes.add(parent[v]);
                if (treeOutDegree[v] > 0) { // not a leaf
                    cutNodes.add(v);
                    bridges.add(new Edge(v, parent[v]));
                }
            }

            if (entryTime[reachableAncestor[v]] < entryTime[reachableAncestor[parent[v]]])
                reachableAncestor[parent[v]] = reachableAncestor[v];
        }
    }
}