#include <bits/stdc++.h>
using namespace std;
const int N = 60;
int n, dp[N][N][N][N];
int f[N][N], g[N][N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      char c;
      cin >> c;
      int a = 0;
      if (c == '#') a = 1;
      f[i][j] = f[i - 1][j] + a;
      g[i][j] = g[i][j - 1] + a;
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = n; j >= 1; j--) {
      for (int u = i; u <= n; u++) {
        for (int v = j; v <= n; v++) {
          dp[i][j][u][v] = max(u - i + 1, v - j + 1);
          for (int k = i; k <= u; k++) {
            if (g[k][v] - g[k][j - 1] == 0) {
              dp[i][j][u][v] =
                  min(dp[i][j][u][v], dp[i][j][k - 1][v] + dp[k + 1][j][u][v]);
            }
            dp[i][j][u][v] =
                min(dp[i][j][u][v], dp[i][j][k][v] + dp[k + 1][j][u][v]);
          }
          for (int k = j; k <= v; k++) {
            if (f[u][k] - f[i - 1][k] == 0) {
              dp[i][j][u][v] =
                  min(dp[i][j][u][v], dp[i][j][u][k - 1] + dp[i][k + 1][u][v]);
            }
            dp[i][j][u][v] =
                min(dp[i][j][u][v], dp[i][j][u][k] + dp[i][k + 1][u][v]);
          }
        }
      }
    }
  }
  cout << dp[1][1][n][n];
}
