#include <bits/stdc++.h>
using namespace std;
int n, f[51][51][51][51];
char s[51][51];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (s[i][j] == '#')
        f[i][j][i][j] = 1;
      else
        f[i][j][i][j] = 0;
  for (int h = 1; h <= n; h++)
    for (int w = 1; w <= n; w++) {
      if (h == 1 && w == 1) continue;
      for (int i = 1; i <= n; i++) {
        if (i + h - 1 > n) break;
        for (int j = 1; j <= n; j++) {
          if (j + w - 1 > n) break;
          f[i][j][i + h - 1][j + w - 1] = max(h, w);
          for (int k = i; k < i + h - 1; k++)
            f[i][j][i + h - 1][j + w - 1] =
                min(f[i][j][i + h - 1][j + w - 1],
                    f[i][j][k][j + w - 1] + f[k + 1][j][i + h - 1][j + w - 1]);
          for (int k = j; k < j + w - 1; k++)
            f[i][j][i + h - 1][j + w - 1] =
                min(f[i][j][i + h - 1][j + w - 1],
                    f[i][j][i + h - 1][k] + f[i][k + 1][i + h - 1][j + w - 1]);
        }
      }
    }
  printf("%d", f[1][1][n][n]);
  return 0;
}
