There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs max(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost.

Input

The first line contains a single integer n (1 ≤ n ≤ 50) — the size of the square grid.

Each of the next n lines contains a string of length n, consisting of characters '.' and '#'. The j-th character of the i-th line is '#' if the cell with coordinates (i, j) is black, otherwise it is white.

Output

Print a single integer — the minimum total cost to paint all cells in white.

Examples

Input


3
###
#.#
###


Output


3


Input


3
...
...
...


Output


0


Input


4
#...
....
....
#...


Output


2


Input


5
#...#
.#.#.
.....
.#...
#....


Output


5

Note

The examples and some of optimal solutions are shown on the pictures below.

<image>
import java.util.*;
import java.io.*;

public class RectanglePaintingOne {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = scanner.nextInt();
        int[][] grid= new int[n][n];
        for(int i = 0; i < n; i++) {
            char[] line = scanner.next().toCharArray();
            for(int j = 0; j < n; j++) {
                grid[i][j] = (line[j] == '.' ? 0 : 1);
            }
        }
        int[][] prefCol = new int[n+1][n+1];
        int[][] prefRow = new int[n+1][n+1];
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                prefRow[i][j] = prefRow[i][j-1] + grid[i-1][j-1];
            }
        }
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                prefCol[i][j] = prefCol[i][j-1] + grid[j-1][i-1];
            }
        }
//        out.println("ROWS");
//        for(int i = 0; i <= n; i++) {
//            for(int j = 0; j <= n; j++) {
//                out.println(i + " "+ j + ": " + prefRow[i][j]);
//            }
//        }
//        out.println("COLS");
//        for(int i = 0; i <=n; i++) {
//            for(int j = 0; j <=n; j++) {
//                out.println(i + " "+ j + ": " + prefCol[i][j]);
//            }
//        }
        int[][][][] best = new int[n][n][n][n];
        for(int k = 0; k < n; k++) {
            for(int l = 0; l < n; l++) {
                for(int i = k; i >= 0; i--) {
                    for(int j = l; j>=0; j--) {
                        int minRow = n;
                        int maxRow = -1;
                        int minCol = n;
                        int maxCol = -1;
                        int next = 0;
                        for(int x = i; x <= k; x++) {
                            if (prefRow[x+1][l+1] - prefRow[x+1][j] > 0) {
                                minRow = Math.min(minRow, x);
                                maxRow = Math.max(maxRow, x);
                            }
                        }
                        for(int x = j; x <= l; x++) {
                            if (prefCol[x+1][k+1] - prefCol[x+1][i] > 0) {
                                minCol = Math.min(minCol, x);
                                maxCol = Math.max(maxCol, x);
                            }
                        }
                        if (minRow == n) next = 0;
                        else next = maxRow - minRow + 1;
                        if (minCol != n) next = Math.max(next, maxCol - minCol + 1);
                        //try prev rows
                        for(int x = i; x < k; x++) {
                            next=Math.min(next, best[i][j][x][l] + best[x+1][j][k][l]);
                        }
                        //try prev cols
                        for(int x = j; x < l; x++) {
                            next = Math.min(next, best[i][j][k][x] + best[i][x+1][k][l]);
                        }
                        best[i][j][k][l] = next;
                    }
                }
            }
        }
//        for(int i = 0; i< n; i++) {
//            for(int j = 0; j < n; j++) {
//                for(int k =i; k < n; k++) {
//                    for(int l = j; l < n; l++) {
//                        out.println(i + " " + j + " " + k + " " + l + ": " + best[i][j][k][l]);
//                    }
//                }
//            }
//        }


        out.println(best[0][0][n-1][n-1]);
        out.flush();
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        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 readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}
