#include <bits/stdc++.h>
using namespace std;
const int maxn = 52;
int dp[maxn][maxn][maxn][maxn];
char s[maxn][maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) scanf("%s", s[i] + 1);
  for (int h = (1); h <= (n); ++h)
    for (int w = (1); w <= (n); ++w)
      for (int x = (1); x <= (n + 1 - h); ++x)
        for (int y = (1); y <= (n + 1 - w); ++y)
          if (h == 1 && w == 1)
            dp[h][w][x][y] = s[x][y] == '#';
          else if (h >= w) {
            dp[h][w][x][y] = h;
            for (int i = (1); i <= (h - 1); ++i)
              dp[h][w][x][y] =
                  min(dp[h][w][x][y], dp[i][w][x][y] + dp[h - i][w][x + i][y]);
          } else {
            dp[h][w][x][y] = w;
            for (int i = (1); i <= (w - 1); ++i)
              dp[h][w][x][y] =
                  min(dp[h][w][x][y], dp[h][i][x][y] + dp[h][w - i][x][y + i]);
          }
  printf("%d\n", dp[n][n][1][1]);
  return 0;
}
