#include <bits/stdc++.h>
using namespace std;
const int N = 32 + 20;
const int oo = 1e9 + 20;
const int MOD = 1e9 + 7;
string a[N];
int dp[N][N][N][N];
int go(int x1, int y1, int x2, int y2) {
  if (x1 == x2 && y1 == y2) return a[x1][y1] == '#';
  int &r = dp[x1][y1][x2][y2];
  if (r == -1) {
    r = max(x2 - x1 + 1, y2 - y1 + 1);
    for (int x = x1; x < x2; x++)
      r = min(r, go(x1, y1, x, y2) + go(x + 1, y1, x2, y2));
    for (int y = y1; y < y2; y++)
      r = min(r, go(x1, y1, x2, y) + go(x1, y + 1, x2, y2));
  }
  return r;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  while (cin >> n) {
    memset(dp, -1, sizeof dp);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    cout << go(0, 0, n - 1, n - 1) << '\n';
  }
}
