#include <bits/stdc++.h>
using namespace std;
string a[55];
long long dp[55][55][55][55];
long long pre[55][55];
long long sum(long long l, long long r, long long u, long long d) {
  return pre[r][d] - pre[r][u - 1] - pre[l - 1][d] + pre[l - 1][u - 1];
}
signed main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i], a[i] = ' ' + a[i];
  for (long long l = 1; l <= n; l++)
    for (long long r = l; r <= n; r++) {
      for (long long u = 1; u <= n; u++)
        for (long long d = u; d <= n; d++) {
          dp[l][r][u][d] = max(r - l + 1, d - u + 1);
        }
    }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      pre[i][j] = pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1];
      pre[i][j] += (a[i][j] == '#');
    }
  }
  for (long long r = 0; r <= n; r++)
    for (long long l = r; l >= 1; l--) {
      for (long long d = 0; d <= n; d++)
        for (long long u = d; u >= 1; u--) {
          for (long long x = l; x <= r; x++) {
            if (sum(x, x, u, d) == 0) {
              dp[l][r][u][d] =
                  min(dp[l][r][u][d], dp[l][x - 1][u][d] + dp[x + 1][r][u][d]);
            }
          }
          for (long long x = u; x <= d; x++) {
            if (sum(l, r, x, x) == 0) {
              dp[l][r][u][d] =
                  min(dp[l][r][u][d], dp[l][r][u][x - 1] + dp[l][r][x + 1][d]);
            }
          }
        }
    }
  cout << dp[1][n][1][n] << endl;
}
