#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 100007;
int dp[51][51][51][51];
int sum[51][51];
char s[51][51];
int rec(int y1, int x1, int y2, int x2) {
  if (dp[y1][x1][y2][x2] != -1) {
    return dp[y1][x1][y2][x2];
  }
  if (y1 > y2 || x1 > x2) {
    return 0;
  }
  if (sum[y2][x2] - sum[y2][x1 - 1] - sum[y1 - 1][x2] + sum[y1 - 1][x1 - 1] ==
      0) {
    return 0;
  }
  int res = max(y2 - y1 + 1, x2 - x1 + 1);
  for (int i = y1; i < y2; i++) {
    res = min(res, rec(y1, x1, i, x2) + rec(i + 1, x1, y2, x2));
  }
  for (int i = x1; i < x2; i++) {
    res = min(res, rec(y1, x1, y2, i) + rec(y1, i + 1, y2, x2));
  }
  return dp[y1][x1][y2][x2] = res;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    for (int j = 1; j <= n; j++) {
      if (s[i][j] == '#') {
        sum[i][j]++;
      }
      sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
    }
  }
  printf("%d\n", rec(1, 1, n, n));
}
