#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int mxn = 53;
int n, q;
int dp[mxn][mxn][mxn][mxn];
string s[mxn];
void input() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
}
void solve() {
  for (int ji = 1; ji <= n; ji++) {
    for (int jj = 1; jj <= n; jj++) {
      for (int i = 0; i + ji <= n; i++) {
        for (int j = 0; j + jj <= n; j++) {
          if (ji == 1 && jj == 1) {
            if (s[i][j] == '#') {
              dp[i + ji][j][i][j + jj] = 1;
            }
            continue;
          }
          dp[i + ji][j][i][j + jj] = max(ji, jj);
          for (int k = 1; k < ji; k++) {
            dp[i + ji][j][i][j + jj] =
                min(dp[i + ji][j][i][j + jj],
                    dp[i + k][j][i][j + jj] + dp[i + ji][j][i + k][j + jj]);
          }
          for (int k = 1; k < jj; k++) {
            dp[i + ji][j][i][j + jj] =
                min(dp[i + ji][j][i][j + jj],
                    dp[i + ji][j][i][j + k] + dp[i + ji][j + k][i][j + jj]);
          }
        }
      }
    }
  }
  cout << dp[n][0][0][n] << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  input(), solve();
  return 0;
}
