#include <bits/stdc++.h>
const int N = 50 + 5;
const int inf = 0x3f3f3f3f;
char m[N][N];
int sum[N][N];
int d[N][N][N][N];
int min(int a, int b) { return a > b ? b : a; }
int max(int a, int b) { return a > b ? a : b; }
int get_sum(int i, int j, int k, int l) {
  if (i > k || j > l)
    return 0;
  else {
    int res = sum[k][l];
    res -= sum[k][j - 1];
    res -= sum[i - 1][l];
    res += sum[i - 1][j - 1];
    return res;
  }
}
int dp(int i, int j, int k, int l) {
  if (d[i][j][k][l] != inf)
    return d[i][j][k][l];
  else {
    if (!get_sum(i, j, k, l))
      return d[i][j][k][l] = 0;
    else {
      d[i][j][k][l] = max(l - j + 1, k - i + 1);
      for (int w = i; w < k; w++)
        d[i][j][k][l] = min(d[i][j][k][l], dp(i, j, w, l) + dp(w + 1, j, k, l));
      for (int w = j; w < l; w++)
        d[i][j][k][l] = min(d[i][j][k][l], dp(i, j, k, w) + dp(i, w + 1, k, l));
      return d[i][j][k][l];
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", m[i] + 1);
  }
  sum[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int u = -1;
      if (m[i][j] == '#')
        u = 1;
      else
        u = 0;
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + u;
    }
  }
  memset(d, inf, sizeof(d));
  printf("%d\n", dp(1, 1, n, n));
  return 0;
}
