#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int MAXN = 50;
int dp[MAXN + 1][MAXN + 1][MAXN + 1][MAXN + 1];
int sp[MAXN + 1][MAXN + 1];
char mat[MAXN + 1][MAXN + 1];
inline int get(int l1, int c1, int l2, int c2) {
  return sp[l2][c2] - sp[l1 - 1][c2] - sp[l2][c1 - 1] + sp[l1 - 1][c1 - 1];
}
int main() {
  int i, j, n;
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> mat[i] + 1;
    for (j = 1; j <= n; j++) {
      sp[i][j] =
          sp[i - 1][j] + sp[i][j - 1] - sp[i - 1][j - 1] + (mat[i][j] == '#');
    }
  }
  for (int lx = 0; lx < n; lx++) {
    for (int ly = 0; ly < n; ly++) {
      for (int x1 = 1; x1 + lx <= n; x1++) {
        for (int y1 = 1; y1 + ly <= n; y1++) {
          int x2 = x1 + lx, y2 = y1 + ly;
          dp[x1][y1][x2][y2] = (get(x1, y1, x2, y2) > 0 ? max(lx, ly) + 1 : 0);
          for (int k = y1; k < y2; k++) {
            dp[x1][y1][x2][y2] = min(dp[x1][y1][x2][y2],
                                     dp[x1][y1][x2][k] + dp[x1][k + 1][x2][y2]);
          }
          for (int k = x1; k < x2; k++) {
            dp[x1][y1][x2][y2] = min(dp[x1][y1][x2][y2],
                                     dp[x1][y1][k][y2] + dp[k + 1][y1][x2][y2]);
          }
        }
      }
    }
  }
  cout << dp[1][1][n][n];
  return 0;
}
