#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
int n, dp[MAXN][MAXN][MAXN][MAXN], a[MAXN][MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  char x;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> x;
      if (x == '#') a[i][j] = 1;
      a[i][j] += a[i - 1][j];
      a[i][j] += a[i][j - 1];
      a[i][j] -= a[i - 1][j - 1];
    }
  }
  for (int lx = 1; lx <= n; lx++) {
    for (int jx = lx; jx <= n; jx++) {
      int ix = jx - lx + 1;
      for (int ly = 1; ly <= n; ly++) {
        for (int jy = ly; jy <= n; jy++) {
          int iy = jy - ly + 1;
          int byk =
              a[jx][jy] - a[jx][iy - 1] - a[ix - 1][jy] + a[ix - 1][iy - 1];
          if (byk == 0) continue;
          dp[ix][iy][jx][jy] = max(lx, ly);
          for (int k = ix; k <= jx - 1; k++)
            dp[ix][iy][jx][jy] = min(dp[ix][iy][jx][jy],
                                     dp[ix][iy][k][jy] + dp[k + 1][iy][jx][jy]);
          for (int k = iy; k <= jy - 1; k++)
            dp[ix][iy][jx][jy] = min(dp[ix][iy][jx][jy],
                                     dp[ix][iy][jx][k] + dp[ix][k + 1][jx][jy]);
        }
      }
    }
  }
  cout << dp[1][1][n][n] << '\n';
  return 0;
}
