#include <bits/stdc++.h>
using namespace std;
char mat[51][51];
int dp[51][51][51][51];
bool used[51][51][51][51];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> mat[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int i1 = i; i1 < n; i1++) {
        for (int j2 = j; j2 < n; j2++) {
          dp[i][j][i1][j2] = max(j2 - j, i1 - i) + 1;
        }
      }
    }
  }
  for (int lni = 1; lni <= n; lni++) {
    for (int lnj = 1; lnj <= n; lnj++) {
      for (int i = 0; i + lni <= n; i++) {
        for (int j = 0; j + lnj <= n; j++) {
          int i2 = i + lni - 1, j2 = j + lnj - 1;
          if (lnj == 1 && lni == 1) {
            dp[i][j][i][j] = (mat[i][j] == '#');
            continue;
          }
          for (int vert = 1; vert < lni; vert++) {
            dp[i][j][i2][j2] =
                min(dp[i][j][i2][j2],
                    dp[i][j][i + vert - 1][j2] + dp[i + vert][j][i2][j2]);
          }
          for (int vert = 1; vert < lnj; vert++) {
            dp[i][j][i2][j2] =
                min(dp[i][j][i2][j2],
                    dp[i][j][i2][j + vert - 1] + dp[i][j + vert][i2][j2]);
          }
        }
      }
    }
  }
  cout << (dp[0][0][n - 1][n - 1]);
  return 0;
}
