#include <bits/stdc++.h>
using namespace std;
const int N = 55;
string square[N];
int dp[N][N][N][N], sum[N][N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> square[i];
    square[i].insert(0, "0");
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] +
                  (square[i][j] == '#');
    }
  }
  for (int x1 = 1; x1 <= n; x1++) {
    for (int y1 = 1; y1 + x1 - 1 <= n; y1++) {
      for (int x2 = 1; x2 <= n; x2++) {
        for (int y2 = 1; y2 + x2 - 1 <= n; y2++) {
          int a = y1 + x1 - 1;
          int b = y2 + x2 - 1;
          int c = y2 - 1;
          int d = y1 - 1;
          if (sum[a][b] - sum[a][c] - sum[d][b] + sum[d][c]) {
            dp[y1][y2][a][b] = max(x1, x2);
          }
          for (int m = y1; m < a; m++) {
            dp[y1][y2][a][b] =
                min(dp[y1][y2][a][b], dp[y1][y2][m][b] + dp[m + 1][y2][a][b]);
          }
          for (int m = y2; m < b; m++) {
            dp[y1][y2][a][b] =
                min(dp[y1][y2][a][b], dp[y1][y2][a][m] + dp[y1][m + 1][a][b]);
          }
        }
      }
    }
  }
  cout << dp[1][1][n][n];
  return 0;
}
