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.Closeable;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Jacob Jiang
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		QuickScanner in = new QuickScanner(inputStream);
		ExtendedPrintWriter out = new ExtendedPrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    private char[][] buf;
    private boolean[][] visited;
    int dfsCount = 0;
    int[] dx = {0, 1, 0, -1};
    int[] dy = {1, 0, -1, 0};
    private int n;
    private int m;

    public void solve(int testNumber, QuickScanner in, ExtendedPrintWriter out) {
        n = in.nextInt();
        m = in.nextInt();
        buf = in.next2DCharArray(n);
        visited = new boolean[n][m];
        int count = 0;
        int someI = -1, someJ = -1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (buf[i][j] == '#') {
                    someI = i;
                    someJ = j;
                    count++;
                }
            }
        }
        if (count <= 2) {
            out.println(-1);
            return;
        }
        int anotherI = -1, anotherJ = -1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (buf[i][j] == '#' && (i != someI || j != someJ)) {
                    anotherI = i;
                    anotherJ = j;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (buf[i][j] == '#') {
                    buf[i][j] = '.';
                    dfsCount = 0;
                    ArrayUtils.fill(visited, false);
                    if (i == someI && j == someJ) {
                        dfs(anotherI, anotherJ);
                    } else {
                        dfs(someI, someJ);
                    }
                    if (dfsCount != count - 1) {
                        out.println(1);
                        return;
                    }
                    buf[i][j] = '#';
                }
            }
        }
        out.println(2);
    }

    private void dfs(int i, int j) {
        visited[i][j] = true;
        dfsCount++;
        for (int k = 0; k < 4; k++) {
            int ni = i + dx[k], nj = j + dy[k];
            if (ni >= 0 && ni < n && nj >= 0 && nj < m && !visited[ni][nj] && buf[ni][nj] == '#') {
                dfs(ni, nj);
            }
        }
    }
}

class QuickScanner implements Iterator<String>, Closeable {
    BufferedReader reader;
    StringTokenizer tokenizer;
    boolean endOfFile = false;

    public QuickScanner(InputStream inputStream){
        reader = new BufferedReader(new InputStreamReader(inputStream));
        try {
            tokenizer = new StringTokenizer(reader.readLine());
        } catch (Exception e) {
            endOfFile = true;
        }
    }

    public boolean hasNext() {
        if (!tokenizer.hasMoreTokens()) {
            try {
                checkNext();
            } catch (NoSuchElementException ignored) {
            }

        }
        return !endOfFile;
    }

    private void checkNext() {
        if (endOfFile) {
            throw new NoSuchElementException();
        }
        try {
            while (!tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (Exception e) {
            endOfFile = true;
            throw new NoSuchElementException();
        }
    }

    public String next() {
        checkNext();
        return tokenizer.nextToken();
    }

    public void remove() {
        throw new UnsupportedOperationException();
    }

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

    public char[] nextCharArray() {
        return next().toCharArray();
    }

    public char[][] next2DCharArray(int n) {
        char[][] result = new char[n][];
        for (int i = 0; i < n; i++) {
            result[i] = nextCharArray();
        }
        return result;
    }

    public void close() {
        try {
            reader.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


}

class ExtendedPrintWriter extends PrintWriter {


    public ExtendedPrintWriter(Writer out) {
        super(out);
    }

    public ExtendedPrintWriter(Writer out, boolean autoFlush) {
        super(out, autoFlush);
    }

    public ExtendedPrintWriter(OutputStream out) {
        super(out);
    }

    public ExtendedPrintWriter(OutputStream out, boolean autoFlush) {
        super(out, autoFlush);
    }

    }

class ArrayUtils {

    public static void fill(boolean[][] array, boolean val) {
        for (boolean[] subArray : array) {
            Arrays.fill(subArray, val);
        }
    }

    }

