#include <bits/stdc++.h>
using namespace std;
long long dp[52][52][52][52];
long long board[52][52];
long long n;
long long temp;
long long solve(long long i, long long j, long long p, long long q) {
  if (dp[i][j][p][q] != -1) {
    return dp[i][j][p][q];
  } else {
    long long ans = max(abs(p - i), abs(j - q));
    for (long long x = i + 1; x < p; x++) {
      ans = min(ans, solve(i, j, x, q) + solve(x, j, p, q));
    }
    for (long long y = j + 1; y < q; y++) {
      ans = min(ans, solve(i, j, p, y) + solve(i, y, p, q));
    }
    dp[i][j][p][q] = ans;
    return dp[i][j][p][q];
  }
  return -1;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long i = 0; i <= 51; i++) {
    for (long long j = 0; j <= 51; j++) {
      for (long long p = 0; p <= 51; p++) {
        for (long long q = 0; q <= 51; q++) {
          dp[i][j][p][q] = -1;
        }
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (long long j = 0; j < s.length(); j++) {
      if (s[j] == '#') {
        board[i][j] = 1;
      } else {
        board[i][j] = 0;
      }
      dp[i][j][i + 1][j + 1] = board[i][j];
    }
  }
  cout << solve(0, 0, n, n) << "\n";
  return 0;
}
