#include <bits/stdc++.h>
using namespace std;
const int N = 55;
char c[N][N];
int n, memo[N][N][N][N];
int solve(int x1, int y1, int x2, int y2) {
  if (memo[x1][y1][x2][y2] != 0x7fffffff) {
    return memo[x1][y1][x2][y2];
  }
  if (x1 == x2 && y1 == y2) {
    memo[x1][y1][x2][y2] = c[x1][y1] == '#';
    return memo[x1][y1][x2][y2];
  }
  memo[x1][y1][x2][y2] = max(y2 - y1 + 1, x2 - x1 + 1);
  for (int j = y1; j < y2; j++) {
    memo[x1][y1][x2][y2] = min(memo[x1][y1][x2][y2],
                               solve(x1, y1, x2, j) + solve(x1, j + 1, x2, y2));
  }
  for (int i = x1; i < x2; i++) {
    memo[x1][y1][x2][y2] = min(memo[x1][y1][x2][y2],
                               solve(x1, y1, i, y2) + solve(i + 1, y1, x2, y2));
  }
  return memo[x1][y1][x2][y2];
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%s", c[i] + 1);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int ii = 0; ii < N; ii++) {
        for (int jj = 0; jj < N; jj++) {
          memo[i][j][ii][jj] = 0x7fffffff;
        }
      }
    }
  }
  cout << solve(1, 1, n, n) << endl;
  return 0;
}
