#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int f[N][N][N][N], a[N][N], n, m;
char s[N][N];
int DP(int X1, int Y1, int X2, int Y2) {
  int &u = f[X1][Y1][X2][Y2];
  if (u >= 0) return u;
  int tmp = a[X2][Y2] - a[X2][Y1 - 1] - a[X1 - 1][Y2] + a[X1 - 1][Y1 - 1];
  u = 0;
  if (tmp > 0) u = max(X2 - X1 + 1, Y2 - Y1 + 1);
  if (u == 0) return u;
  for (int i = X1; i < X2; i++)
    u = min(u, DP(X1, Y1, i, Y2) + DP(i + 1, Y1, X2, Y2));
  for (int i = Y1; i < Y2; i++)
    u = min(u, DP(X1, Y1, X2, i) + DP(X1, i + 1, X2, Y2));
  return u;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int i2 = i; i2 <= n; i2++)
        for (int j2 = j; j2 <= n; j2++) f[i][j][i2][j2] = -1;
  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++)
      a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1] + (s[i][j] == '#');
  printf("%d\n", DP(1, 1, n, n));
}
