#include <bits/stdc++.h>
const int N = 50 + 5;
int n, pre[N][N], dp[N][N][N][N];
char s[N][N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      pre[i][j] = pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1] +
                  (s[i][j] == '#' ? 1 : 0);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 0; k < i; k++) {
        for (int l = 0; l < j; l++) {
          if (pre[i][j] - pre[i - k - 1][j] - pre[i][j - l - 1] +
                  pre[i - k - 1][j - l - 1] ==
              0) {
            dp[i - k][i][j - l][j] = 0;
            continue;
          }
          dp[i - k][i][j - l][j] = std::max(k + 1, l + 1);
          if (k > l) {
            for (int x = 0; x < k; x++) {
              dp[i - k][i][j - l][j] = std::min(
                  dp[i - k][i][j - l][j], dp[i - k][i - k + x][j - l][j] +
                                              dp[i - k + x + 1][i][j - l][j]);
            }
          } else {
            for (int x = 0; x < l; x++) {
              dp[i - k][i][j - l][j] = std::min(
                  dp[i - k][i][j - l][j], dp[i - k][i][j - l][j - l + x] +
                                              dp[i - k][i][j - l + x + 1][j]);
            }
          }
        }
      }
    }
  }
  printf("%d\n", dp[1][n][1][n]);
  return 0;
}
