#include <bits/stdc++.h>
using namespace std;
char a[51][51];
int n;
int dp[51][51][51][51];
int f(int i, int j, int ii, int jj) {
  if (i == ii && jj == j) {
    if (a[i][j] == '#')
      return 1;
    else
      return 0;
  }
  if (dp[i][j][ii][jj] != -1) return dp[i][j][ii][jj];
  int ans = max(ii - i + 1, jj - j + 1);
  for (int k = i; k < ii; k++) {
    ans = min(ans, f(k + 1, j, ii, jj) + f(i, j, k, jj));
  }
  for (int k = j; k < jj; k++) {
    ans = min(ans, f(i, k + 1, ii, jj) + f(i, j, ii, k));
  }
  return dp[i][j][ii][jj] = ans;
}
int main() {
  ;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  memset(dp, -1, sizeof dp);
  cout << f(0, 0, n - 1, n - 1);
}
