#include <bits/stdc++.h>
using namespace std;
long long n, a[55][55];
long long dp[55][55][55][55] = {0};
long long su[55][55] = {0};
char ch;
long long get_sum(long long x1, long long y1, long long x2, long long y2) {
  return su[x2][y2] - su[x1 - 1][y2] - su[x2][y1 - 1] + su[x1 - 1][y1 - 1];
}
int main() {
  memset(dp, 0x3f, sizeof(dp));
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      cin >> ch;
      if (ch == '#') {
        a[i][j] = 1;
      }
      su[i][j] = su[i - 1][j] + su[i][j - 1] - su[i - 1][j - 1] + a[i][j];
    }
  }
  for (long long w = 0; w < n; w++) {
    for (long long h = 0; h < n; h++) {
      for (long long i = 1; i <= n; i++) {
        long long k = i + w;
        if (k > n) break;
        for (long long j = 1; j <= n; j++) {
          long long l = j + h;
          if (l > n) break;
          dp[i][j][k][l] = max(w, h) + 1;
          if (get_sum(i, j, k, l) == 0) dp[i][j][k][l] = 0;
          for (long long di = i; di < k; di++) {
            dp[i][j][k][l] =
                min(dp[i][j][k][l], dp[i][j][di][l] + dp[di + 1][j][k][l]);
          }
          for (long long dj = j; dj < l; dj++) {
            dp[i][j][k][l] =
                min(dp[i][j][k][l], dp[i][j][k][dj] + dp[i][dj + 1][k][l]);
          }
        }
      }
    }
  }
  cout << dp[1][1][n][n] << endl;
  return 0;
}
