#include <bits/stdc++.h>
using namespace std;
constexpr long long MAXN = 55;
long long dp[MAXN][MAXN][MAXN][MAXN], pref[MAXN][MAXN];
long long get(long long i, long long j, long long x, long long y) {
  return pref[x][y] - pref[x][j - 1] - pref[i - 1][y] + pref[i - 1][j - 1];
}
signed main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < MAXN; i++) {
    memset(pref[i], 0, sizeof pref[i]);
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      for (long long x = i; x <= n; x++) {
        for (long long y = j; y <= n; y++) {
          dp[i][j][x][y] = max(x - i + 1, y - j + 1);
        }
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (long long j = 0; j < n; j++) {
      pref[i + 1][j + 1] = pref[i + 1][j] + pref[i][j + 1] - pref[i][j];
      if (s[j] == '#') pref[i + 1][j + 1]++;
    }
  }
  for (long long x = 1; x <= n; x++) {
    for (long long y = 1; y <= n; y++) {
      for (long long i = x; i >= 1; i--) {
        for (long long j = y; j >= 1; j--) {
          long long &cur = dp[i][j][x][y];
          if (get(i, j, x, y) == 0) {
            cur = 0;
            continue;
          }
          for (long long k = i; k < x; k++) {
            cur = min(cur, dp[i][j][k][y] + dp[k + 1][j][x][y]);
          }
          for (long long k = j; k < y; k++) {
            cur = min(cur, dp[i][j][x][k] + dp[i][k + 1][x][y]);
          }
        }
      }
    }
  }
  cout << dp[1][1][n][n];
  return 0;
}
