#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
int arr[55][55];
int sum[55][55];
int n;
bool calc[55][55][55][55];
long long dp[55][55][55][55];
int query(int top, int left, int bot, int right) {
  return sum[bot][right] - sum[bot][left - 1] - sum[top - 1][right] +
         sum[top - 1][left - 1];
}
long long solve(int top, int left, int bot, int right) {
  if (query(top, left, bot, right) == 0) return 0LL;
  if (calc[top][left][bot][right]) return dp[top][left][bot][right];
  calc[top][left][bot][right] = 1;
  int w = right - left + 1;
  int h = bot - top + 1;
  long long ret = max(h, w) * 1LL;
  for (int i = top + 1; i <= bot; i++) {
    ret = min(ret, solve(top, left, i - 1, right) + solve(i, left, bot, right));
  }
  for (int i = left + 1; i <= right; i++) {
    ret = min(ret, solve(top, left, bot, i - 1) + solve(top, i, bot, right));
  }
  return dp[top][left][bot][right] = ret;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    char tmp;
    for (int j = 1; j <= n; j++) {
      cin >> tmp;
      if (tmp == '#') arr[i][j] = 1;
      sum[i][j] = arr[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
    }
  }
  cout << solve(1, 1, n, n);
}
