#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const int LG = 22;
int dp[51][51][51][51];
int n;
int foo(int c1, int c2, int r1, int r2) {
  if (r1 > r2 or c1 > c2) return 0;
  if (dp[c1][c2][r1][r2] != -1) return dp[c1][c2][r1][r2];
  int res = max(c2 - c1 + 1, r2 - r1 + 1);
  for (int i = c1; i < c2; i++)
    res = min(res, foo(c1, i, r1, r2) + foo(i + 1, c2, r1, r2));
  for (int i = r1; i < r2; i++)
    res = min(res, foo(c1, c2, r1, i) + foo(c1, c2, i + 1, r2));
  return dp[c1][c2][r1][r2] = res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof(dp));
  cin >> n;
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (s[i][j] == '.') {
        dp[j][j][i][i] = 0;
      } else {
        dp[j][j][i][i] = 1;
      }
    }
  }
  cout << foo(0, n - 1, 0, n - 1) << endl;
  return 0;
}
