#include <bits/stdc++.h>
using namespace std;
int n, dp[50][50][50][50];
char g[50][50];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) scanf(" %c", &g[i][j]);
  for (int s1 = 0; s1 < n; s1++)
    for (int s2 = 0; s2 < n; s2++) {
      for (int i = 0; i + s1 < n; i++)
        for (int j = 0; j + s2 < n; j++) {
          int r1 = i, r2 = i + s1, c1 = j, c2 = j + s2;
          if (!s1 && !s2) {
            dp[r1][c1][r2][c2] = (g[i][j] == '#');
            continue;
          }
          int ans = max(s1 + 1, s2 + 1);
          for (int a = r1; a < r2; a++)
            ans = min(ans, dp[r1][c1][a][c2] + dp[a + 1][c1][r2][c2]);
          for (int a = c1; a < c2; a++)
            ans = min(ans, dp[r1][c1][r2][a] + dp[r1][a + 1][r2][c2]);
          dp[r1][c1][r2][c2] = ans;
        }
    }
  printf("%d\n", dp[0][0][n - 1][n - 1]);
}
