#include <bits/stdc++.h>
using namespace std;
const int N = 50 + 5;
const int mod = 1e9 + 7;
int n;
char G[N][N];
int dp[N][N][N][N];
int DFS(int xl, int xr, int yl, int yr) {
  if (dp[xl][xr][yl][yr] != -1) return dp[xl][xr][yl][yr];
  if (xl == xr && yl == yr) return G[xl][yl] == '#';
  int ans = max(xr - xl + 1, yr - yl + 1);
  for (int x = xl; x <= xr - 1; x++)
    ans = min(ans, DFS(xl, x, yl, yr) + DFS(x + 1, xr, yl, yr));
  for (int y = yl; y <= yr - 1; y++)
    ans = min(ans, DFS(xl, xr, yl, y) + DFS(xl, xr, y + 1, yr));
  return dp[xl][xr][yl][yr] = ans;
}
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) scanf("%s", G[i] + 1);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        for (int p = 1; p <= n; p++)
          for (int q = 1; q <= n; q++) dp[i][j][p][q] = -1;
    printf("%d\n", DFS(1, n, 1, n));
  }
  return 0;
}
