#include <bits/stdc++.h>
using namespace std;
int n;
int pre[55][55][55][55];
int dp[55][55][55][55];
int bang[55][55];
int main() {
  ios_base::sync_with_stdio(false);
  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;
      if (c == '#') bang[i][j] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int p = i; p <= n; p++) {
        for (int q = j; q <= n; q++) {
          pre[i][j][p][q] = pre[i][j][p - 1][q] + pre[i][j][p][q - 1] -
                            pre[i][j][p - 1][q - 1] + bang[p][q];
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int p = i; p >= 1; p--) {
        for (int q = j; q >= 1; q--) {
          dp[i][j][p][q] = max(i - p + 1, j - q + 1);
          if (p == i && q == j) {
            dp[i][j][p][q] = bang[i][j];
            continue;
          }
          if (pre[p][q][i][j] == 0) {
            dp[i][j][p][q] = 0;
            continue;
          }
          for (int k = p; k < i; k++) {
            dp[i][j][p][q] =
                min(dp[i][j][p][q], dp[k][j][p][q] + dp[i][j][k + 1][q]);
          }
          for (int k = q; k < j; k++) {
            dp[i][j][p][q] =
                min(dp[i][j][p][q], dp[i][k][p][q] + dp[i][j][p][k + 1]);
          }
        }
      }
    }
  }
  cout << dp[n][n][1][1];
}
