#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
int f[maxn][maxn];
int dp[maxn][maxn][maxn][maxn];
int solve(int xa, int ya, int xb, int yb) {
  if (xa > xb || ya > yb) return 0;
  if (dp[xa][ya][xb][yb] != -1) return dp[xa][ya][xb][yb];
  int cnt = f[xb][yb] - f[xa - 1][yb] - f[xb][ya - 1] + f[xa - 1][ya - 1];
  int& ret = dp[xa][ya][xb][yb];
  ret = (cnt == 0 ? 0 : max(xb - xa + 1, yb - ya + 1));
  for (int xc = xa; xc <= xb; ++xc) {
    ret = min(ret, solve(xa, ya, xc, yb) + solve(xc + 1, ya, xb, yb));
  }
  for (int yc = ya; yc <= yb; ++yc) {
    ret = min(ret, solve(xa, ya, xb, yc) + solve(xa, yc + 1, xb, yb));
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  memset(dp, -1, sizeof dp);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1];
      char c;
      cin >> c;
      if (c == '#') f[i][j]++;
    }
  }
  cout << solve(1, 1, n, n) << endl;
  return 0;
}
