#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
int n;
char s[MAXN][MAXN];
int f[MAXN][MAXN][MAXN][MAXN];
int find(int x1, int y1, int x2, int y2) {
  if (f[x1][y1][x2][y2] != -1) return f[x1][y1][x2][y2];
  if (x1 == x2 && y1 == y2) {
    if (s[x1][y1] == '#')
      f[x1][y1][x2][y2] = 1;
    else
      f[x1][y1][x2][y2] = 0;
    return f[x1][y1][x2][y2];
  }
  f[x1][y1][x2][y2] = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int i = x1; i < x2; i++) {
    if (f[x1][y1][i][y2] == -1) find(x1, y1, i, y2);
    if (f[i + 1][y1][x2][y2] == -1) find(i + 1, y1, x2, y2);
    f[x1][y1][x2][y2] =
        min(f[x1][y1][x2][y2], f[x1][y1][i][y2] + f[i + 1][y1][x2][y2]);
  }
  for (int j = y1; j < y2; j++) {
    if (f[x1][y1][x2][j] == -1) find(x1, y1, x2, j);
    if (f[x1][j + 1][x2][y2] == -1) find(x1, j + 1, x2, y2);
    f[x1][y1][x2][y2] =
        min(f[x1][y1][x2][y2], f[x1][y1][x2][j] + f[x1][j + 1][x2][y2]);
  }
  return f[x1][y1][x2][y2];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  memset(f, -1, sizeof(f));
  printf("%d\n", find(1, 1, n, n));
  return 0;
}
