#include <bits/stdc++.h>
using namespace std;
int dp[55][55][55][55];
int G[55][55];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      char ch;
      cin >> ch;
      G[i][j] = (ch == '#');
    }
  }
  for (int i = n; i > 0; i--) {
    for (int j = n; j > 0; j--) {
      for (int ii = i; ii <= n; ii++) {
        for (int jj = j; jj <= n; jj++) {
          if (i == ii && j == jj) {
            dp[i][j][ii][jj] = G[i][j];
            continue;
          }
          dp[i][j][ii][jj] = max(ii - i + 1, jj - j + 1);
          for (int k = i; k < ii; k++)
            dp[i][j][ii][jj] =
                min(dp[i][j][ii][jj], dp[i][j][k][jj] + dp[k + 1][j][ii][jj]);
          for (int k = j; k < jj; k++)
            dp[i][j][ii][jj] =
                min(dp[i][j][ii][jj], dp[i][j][ii][k] + dp[i][k + 1][ii][jj]);
        }
      }
    }
  }
  cout << dp[1][1][n][n] << endl;
  return 0;
}
