#include <bits/stdc++.h>
using namespace std;
int n;
char a[55][55];
int f[55][55][55][55];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
    if (ch == -1) return 0;
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) f[i][j][i][j] = (a[i][j] == '#');
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= n; y++) {
      if (x == 1 && y == 1) continue;
      for (int i = 1; i + x - 1 <= n; i++)
        for (int j = 1; j + y - 1 <= n; j++) {
          f[i][j][i + x - 1][j + y - 1] = max(x, y);
          for (int k = i; k < i + x - 1; k++)
            f[i][j][i + x - 1][j + y - 1] =
                min(f[i][j][i + x - 1][j + y - 1],
                    f[i][j][k][j + y - 1] + f[k + 1][j][i + x - 1][j + y - 1]);
          for (int k = j; k < j + y - 1; k++)
            f[i][j][i + x - 1][j + y - 1] =
                min(f[i][j][i + x - 1][j + y - 1],
                    f[i][j][i + x - 1][k] + f[i][k + 1][i + x - 1][j + y - 1]);
        }
    }
  printf("%d\n", f[1][1][n][n]);
  return 0;
}
