#include <bits/stdc++.h>
using namespace std;
long long dp[51][51][51][51];
int main() {
  int n;
  cin >> n;
  long long d[n + 1][n + 1];
  char x;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> x;
      d[i][j] = 0;
      if (x == '#') d[i][j] = 1;
    }
  }
  for (long long l1 = 1; l1 <= n; l1++) {
    for (long long l2 = 1; l2 <= n; l2++) {
      for (int i = 1; i + l1 - 1 <= n; i++) {
        for (int j = 1; j + l2 - 1 <= n; j++) {
          long long a = i + l1 - 1;
          long long b = j + l2 - 1;
          long long &p = dp[i][j][a][b];
          if (l1 == 1 && l2 == 1 && !d[i][j])
            p = 0;
          else
            p = max(l1, l2);
          for (int k = i; k < a; k++)
            p = min(p, dp[i][j][k][b] + dp[k + 1][j][a][b]);
          for (int k = j; k < b; k++)
            p = min(p, dp[i][j][a][k] + dp[i][k + 1][a][b]);
        }
      }
    }
  }
  cout << dp[1][1][n][n];
}
