#include <bits/stdc++.h>
using namespace std;
long long const max_N = 52;
long long N, DP[max_N][max_N][max_N][max_N], mat[max_N][max_N],
    pre_sum[max_N][max_N];
string str;
long long paint_cost(long long x1, long long y1, long long x2, long long y2) {
  long long &res = DP[x1][y1][x2][y2];
  if (res != -1) return res;
  long long min_cost = max(x2 - x1 + 1, y2 - y1 + 1);
  long long cost;
  for (int x3 = x1; x3 < x2; x3++) {
    cost = paint_cost(x1, y1, x3, y2) + paint_cost(x3 + 1, y1, x2, y2);
    min_cost = min(min_cost, cost);
  }
  for (int y3 = y1; y3 < y2; y3++) {
    cost = paint_cost(x1, y1, x2, y3) + paint_cost(x1, y3 + 1, x2, y2);
    min_cost = min(cost, min_cost);
  }
  return res = min_cost;
}
int32_t main() {
  cin >> N;
  memset(DP, -1, sizeof(DP));
  for (int i = 1; i <= N; i++) {
    cin >> str;
    for (int j = 1; j <= N; j++) DP[i][j][i][j] = (str[j - 1] == '#');
  }
  cout << paint_cost(1, 1, N, N) << "\n";
  return 0;
}
