#include <bits/stdc++.h>
using namespace std;
long long n, m;
char ch[60][60];
long long dp[60][60][60][60];
long long solve(int i, int j, int li, int lj) {
  if (i > li || j > lj) {
    return 0;
  }
  if (li == i && lj == j) {
    if (ch[i][j] == '#') return 1;
    return 0;
  }
  if (dp[i][j][li][lj] != -1) return dp[i][j][li][lj];
  long long sol = max(li - i + 1, lj - j + 1);
  for (int k = i; k < li; k++) {
    sol = min(sol, solve(i, j, k, lj) + solve(k + 1, j, li, lj));
  }
  for (int k = j; k < lj; k++) {
    sol = min(sol, solve(i, j, li, k) + solve(i, k + 1, li, lj));
  }
  return dp[i][j][li][lj] = sol;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  m = n;
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> ch[i][j];
    }
  }
  long long d = solve(0, 0, n - 1, m - 1);
  cout << d << endl;
  return 0;
}
