#include <bits/stdc++.h>
using namespace std;
const int N = 60;
int dp[N][N][N][N];
int n;
string x[N];
int go(int x1, int x2, int y1, int y2) {
  if (x1 > x2 or y1 > y2) return 0;
  if (x1 == x2 and y1 == y2) return x[x1][y1] == '#';
  if (dp[x1][x2][y1][y2] != -1) return dp[x1][x2][y1][y2];
  int best = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int i = x1; i < x2; i++) {
    best = min(best, go(x1, i, y1, y2) + go(i + 1, x2, y1, y2));
  }
  for (int i = y1; i < y2; i++) {
    best = min(best, go(x1, x2, y1, i) + go(x1, x2, i + 1, y2));
  }
  return dp[x1][x2][y1][y2] = best;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  memset(dp, -1, sizeof dp);
  cout << go(0, n - 1, 0, n - 1) << '\n';
}
