#include <bits/stdc++.h>
using namespace std;
int n;
char G[60][60];
int dp[51][51][51][51];
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 i = xl; i < xr; i++)
    ans = min(ans, DFS(xl, i, yl, yr) + DFS(i + 1, xr, yl, yr));
  for (int i = yl; i < yr; i++)
    ans = min(ans, DFS(xl, xr, yl, i) + DFS(xl, xr, i + 1, yr));
  dp[xl][xr][yl][yr] = ans;
  return ans;
}
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) scanf("%s", &G[i]);
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= n; j++)
        for (int k = 0; k <= n; k++)
          for (int q = 0; q <= n; q++) dp[i][j][k][q] = -1;
    printf("%d\n", DFS(0, n - 1, 0, n - 1));
  }
  return 0;
}
