#include <bits/stdc++.h>
using namespace std;
int dp[52][52][52][52];
int cnt[52][52];
int get(int x1, int y1, int x2, int y2) {
  return cnt[x2][y2] - cnt[x1 - 1][y2] - cnt[x2][y1 - 1] + cnt[x1 - 1][y1 - 1];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cnt[i][j] = cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1] +
                  (s[i - 1][j - 1] == '#');
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int k = i; k > 0; k--) {
      for (int j = 1; j <= n; j++) {
        for (int l = j; l > 0; l--) {
          dp[k][l][i][j] = max(i - k + 1, j - l + 1);
          for (int row = k; row <= i; row++) {
            if (!get(row, l, row, j))
              dp[k][l][i][j] = min(dp[k][l][i][j],
                                   dp[k][l][row - 1][j] + dp[row + 1][l][i][j]);
          }
          for (int col = l; col <= j; col++) {
            if (!get(k, col, i, col))
              dp[k][l][i][j] = min(dp[k][l][i][j],
                                   dp[k][l][i][col - 1] + dp[k][col + 1][i][j]);
          }
        }
      }
    }
  }
  cout << dp[1][1][n][n] << endl;
  return 0;
}
