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

public class F implements Runnable {
	public static void main (String[] args) {new Thread(null, new F(), "_cf", 1 << 28).start();}

	int n;
	char[][] g;
	int[][] pref;
	int[][][] pc;
	int[] dp;
	
	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		n = fs.nextInt();
		g = new char[n][n];
		for(int i = 0; i < n; i++) g[i] = fs.next().toCharArray();
		pc = new int[n][n][n];
		
		pref = new int[n][n];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				pref[i][j] = g[i][j] == '#' ? 1 : 0;
				if(j > 0) pref[i][j] += pref[i][j-1];
			}
		}
		
		for(int len = 0; len < n; len++) {
			for(int i = 0; i < n; i++) {
				if(i+len >= n) break;
				Arrays.fill(pc[i][i+len], -1);
				solve1(i, i+len, 0);
			}
		}
		
		for(int i = 0; i < n; i++) {
			for(int j = i; j < n; j++) {
				Arrays.fill(pc[i][j], -1);
				solve1(i, j, 0);
//				System.out.println(i + " " + j + " " + Arrays.toString(pc[i][j]));
			}
		}
		dp = new int[n];
		Arrays.fill(dp, -1);
		out.println(solve(0));
		
		out.close();
	}
	
	int solve(int row) {
		if(row == n) return 0;
		if(dp[row] != -1) return dp[row];
		int res = Integer.MAX_VALUE;
		for(int row2 = row; row2 < n; row2++) {
			int cost = pc[row][row2][0];
			res = Math.min(res, cost+solve(row2+1));
		}
		return dp[row] = res;
	}
	
	int solve1(int u, int d, int l) {
		if(l == n) {
			return 0;
		}
		int ret = pc[u][d][l];
		if(ret != -1) return ret;
		int res = Integer.MAX_VALUE;
		
		boolean clear = true;
		for(int i = u; i <= d; i++) clear &= g[i][l] == '.';
		if(clear) res = Math.min(res, solve1(u, d, l+1));
		
		for(int r = l; r < n; r++) {
			int add = r-l+1;
			int trim1 = u;
			while(trim1 < d && pref[trim1][r] - (l > 0 ? pref[trim1][l-1] : 0) == 0) trim1++;
			
			int trim = d;
			while(trim > trim1 && pref[trim][r] - (l > 0 ? pref[trim][l-1] : 0) == 0) trim--;
			add = Math.max(trim-trim1+1, add);
			res = Math.min(res, add+solve1(u, d, r+1));
		}
		
		for(int sp = u; sp < d; sp++) {
			res = Math.min(res, pc[u][sp][l]+pc[sp+1][d][l]);
		}
		
		return pc[u][d][l] = res;
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}