#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void ran() { srand(chrono::steady_clock::now().time_since_epoch().count()); }
long long get_rand() {
  long long a = rand();
  long long b = rand();
  return a * (RAND_MAX + 1ll) + b;
}
void usaco() {
  freopen("problem.in", "r", stdin);
  freopen("problem.out", "w", stdout);
}
const int MXN = 51;
int dp[MXN][MXN][MXN][MXN];
int n;
string r[MXN];
int pf[MXN][MXN];
bool empty(int l, int r, int u, int d) {
  return (pf[r][d] + pf[l - 1][u - 1] - pf[r][u - 1] - pf[l - 1][d]) == 0;
}
int solve(int l, int r, int u, int d) {
  if (l > r) return 0;
  if (u > d) return 0;
  if (dp[l][r][u][d] != -1) return dp[l][r][u][d];
  int sc = max((r - l + 1), (d - u + 1));
  for (int i = l; i <= r; i++) {
    if (empty(i, i, u, d)) {
      sc = min(sc, solve(l, i - 1, u, d) + solve(i + 1, r, u, d));
    }
  }
  for (int i = u; i <= d; i++) {
    if (empty(l, r, i, i)) {
      sc = min(sc, solve(l, r, u, i - 1) + solve(l, r, i + 1, d));
    }
  }
  return dp[l][r][u][d] = sc;
}
signed main() {
  ran();
  fast();
  memset(dp, -1, sizeof dp);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> r[i];
    for (int j = 1; j <= n; j++) {
      pf[i][j] =
          pf[i - 1][j] + pf[i][j - 1] - pf[i - 1][j - 1] + (r[i][j - 1] == '#');
    }
  }
  cout << solve(1, n, 1, n) << endl;
}
