#include <bits/stdc++.h>
const int N = 55;
using namespace std;
int n;
int sum[N][N], f[N][N][N][N];
void READ() {
  char x;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("\n");
    for (int j = 1; j <= n; j++) {
      scanf("%c", &x);
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      if (x == '#') sum[i][j]++;
    }
  }
}
void SOLVE() {
  memset(f, 0, sizeof(f));
  for (int H = 1; H <= n; H++)
    for (int lh = 1; lh <= n - H + 1; lh++) {
      int rh = lh + H - 1;
      for (int W = 1; W <= n; W++)
        for (int lw = 1; lw <= n - W + 1; lw++) {
          int rw = lw + W - 1;
          f[lh][rh][lw][rw] = max(W, H);
          for (int i = lh; i <= rh; i++)
            if (sum[i][rw] - sum[i - 1][rw] - sum[i][lw - 1] +
                    sum[i - 1][lw - 1] ==
                0) {
              f[lh][rh][lw][rw] =
                  min(f[lh][rh][lw][rw],
                      f[lh][i - 1][lw][rw] + f[i + 1][rh][lw][rw]);
            }
          for (int i = lw; i <= rw; i++)
            if (sum[rh][i] - sum[lh - 1][i] - sum[rh][i - 1] +
                    sum[lh - 1][i - 1] ==
                0) {
              f[lh][rh][lw][rw] =
                  min(f[lh][rh][lw][rw],
                      f[lh][rh][lw][i - 1] + f[lh][rh][i + 1][rw]);
            }
        }
    }
  printf("%d\n", f[1][n][1][n]);
}
int main() {
  READ();
  SOLVE();
  return 0;
}
