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