#include <bits/stdc++.h>
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline void sub(long long &a, long long b) {
  a -= b;
  if (a < 0) a += 998244353;
}
inline void add(long long &a, long long b) {
  a += b;
  if (a >= 998244353) a -= 998244353;
}
template <typename T>
inline T const &MAX(T const &a, T const &b) {
  return a > b ? a : b;
}
template <typename T>
inline T const &MIN(T const &a, T const &b) {
  return a < b ? a : b;
}
inline long long qp(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 998244353;
    a = a * a % 998244353, b >>= 1;
  }
  return ans;
}
inline long long qp(long long a, long long b, long long c) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % c;
    a = a * a % c, b >>= 1;
  }
  return ans;
}
using namespace std;
const unsigned long long ba = 233;
const double eps = 1e-5;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 50 + 10, maxn = 2000000 + 10, inf = 0x3f3f3f3f;
char s[N][N];
int dp[N][N][N][N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int l1 = 1; l1 <= n; l1++)
    for (int l2 = 1; l2 <= n; l2++)
      for (int i = 1, j = i + l1 - 1; j <= n; i++, j++)
        for (int k = 1, l = k + l2 - 1; l <= n; k++, l++) {
          if (l1 == 1 && l2 == 1)
            dp[i][j][k][l] = (s[i][k] == '#');
          else
            dp[i][j][k][l] = max(l1, l2);
          for (int p = i; p < j; p++)
            dp[i][j][k][l] =
                min(dp[i][j][k][l], dp[i][p][k][l] + dp[p + 1][j][k][l]);
          for (int p = k; p < l; p++)
            dp[i][j][k][l] =
                min(dp[i][j][k][l], dp[i][j][k][p] + dp[i][j][p + 1][l]);
        }
  printf("%d\n", dp[1][n][1][n]);
  return 0;
}
