#include <bits/stdc++.h>
using namespace std;
int a[55][55], f[55][55][55][55];
int main() {
  int n;
  char str[55];
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) {
    scanf("%s", str + 1);
    for (register int j = 1; j <= n; ++j) f[i][j][i][j] = (str[j] == '#');
  }
  for (register int l1 = 1; l1 <= n; ++l1)
    for (register int l2 = 1; l2 <= n; ++l2)
      if (l1 + l2 > 2) {
        for (register int i = 1; i + l1 - 1 <= n; ++i)
          for (register int j = 1; j + l2 - 1 <= n; ++j) {
            int ii = i + l1 - 1, jj = j + l2 - 1;
            f[i][j][ii][jj] = max(l1, l2);
            for (register int k = i; k < ii; ++k)
              f[i][j][ii][jj] =
                  min(f[i][j][ii][jj], f[i][j][k][jj] + f[k + 1][j][ii][jj]);
            for (register int k = j; k < jj; ++k)
              f[i][j][ii][jj] =
                  min(f[i][j][ii][jj], f[i][j][ii][k] + f[i][k + 1][ii][jj]);
          }
      }
  return 0 * printf("%d", f[1][1][n][n]);
}
