#include <bits/stdc++.h>
using namespace std;
const int N = 55;
const int inf = 1e9;
char mat[N][N];
int dp[N][N][N][N];
short done[N][N][N][N];
short timer = 0;
int n;
int first(int r1, int c1, int r2, int c2) {
  if (r1 == r2 && c1 == c2) return mat[r1][c1] == '#';
  int &ans = dp[r1][c1][r2][c2];
  if (done[r1][c1][r2][c2] != timer) {
    done[r1][c1][r2][c2] = timer;
    ans = max(r2 - r1 + 1, c2 - c1 + 1);
    for (auto rk = (r1) - ((r1) > (r2)); rk != r2 - ((r1) > (r2));
         rk += 1 - 2 * ((r1) > (r2)))
      ans = min(ans, first(r1, c1, rk, c2) + first(rk + 1, c1, r2, c2));
    for (auto ck = (c1) - ((c1) > (c2)); ck != c2 - ((c1) > (c2));
         ck += 1 - 2 * ((c1) > (c2)))
      ans = min(ans, first(r1, c1, r2, ck) + first(r1, ck + 1, r2, c2));
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  while (cin >> n) {
    for (auto r = (1) - ((1) > (n + 1)); r != n + 1 - ((1) > (n + 1));
         r += 1 - 2 * ((1) > (n + 1)))
      for (auto c = (1) - ((1) > (n + 1)); c != n + 1 - ((1) > (n + 1));
           c += 1 - 2 * ((1) > (n + 1)))
        cin >> mat[r][c];
    ++timer;
    cout << first(1, 1, n, n) << '\n';
  }
  return 0;
}
