#include <bits/stdc++.h>
using namespace std;
int ar[50 + 9];
int pr[50 + 9];
int G[50 + 9][50 + 9];
int SUM[50 + 9][50 + 9];
int dp[50 + 9][50 + 9][50 + 9][50 + 9];
int vis[50 + 9][50 + 9][50 + 9][50 + 9];
int check(int l1, int l2, int r1, int r2) {
  if ((SUM[l2][r2] - SUM[l1 - 1][r2] - SUM[l2][r1 - 1] + SUM[l1 - 1][r1 - 1]) ==
      0)
    return 0;
  if ((SUM[l2][r2] - SUM[l1 - 1][r2] - SUM[l2][r1 - 1] + SUM[l1 - 1][r1 - 1]) ==
      (l2 - l1 + 1) * (r2 - r1 + 1))
    return max((l2 - l1 + 1), (r2 - r1 + 1));
  if (vis[l1][l2][r1][r2]) return dp[l1][l2][r1][r2];
  vis[l1][l2][r1][r2] = 1;
  int ans = max((l2 - l1 + 1), (r2 - r1 + 1)), i;
  for (i = l1; i < l2; i++)
    ans = min(ans, check(l1, i, r1, r2) + check(i + 1, l2, r1, r2));
  for (i = r1; i < r2; i++)
    ans = min(ans, check(l1, l2, r1, i) + check(l1, l2, i + 1, r2));
  return dp[l1][l2][r1][r2] = ans;
}
string aa;
int main() {
  int i, j, k, l, n, m = 0, tot, temp, curr, val, prev, a, b, c, t, ans,
                     main_flag, flag, x, y, siz, w, h, d, ii, jj, xx, yy, ind,
                     len;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> aa;
    for (j = 1; j <= n; j++) {
      if (aa[j - 1] == '#') {
        G[i][j] = 1;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      SUM[i][j] = SUM[i - 1][j] + SUM[i][j - 1] - SUM[i - 1][j - 1] + G[i][j];
    }
  }
  ans = n;
  ans = min(ans, check(1, n, 1, n));
  cout << ans << endl;
}
