#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[52];
int sum[52][52];
int dp[52][52][52][52];
int Sum(int i1, int j1, int i2, int j2) {
  return sum[i2][j2] - sum[i1 - 1][j2] - sum[i2][j1 - 1] + sum[i1 - 1][j1 - 1];
}
int main() {
  scanf("%d\n", &n);
  for (int i = 0; i < n; ++i) {
    gets(s);
    for (int j = 0; j < n; ++j) {
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      if (s[j] == '#') ++sum[i][j];
    }
  }
  for (int i1 = n - 1; i1 >= 0; --i1)
    for (int j1 = n - 1; j1 >= 0; --j1)
      for (int i2 = i1; i2 < n; ++i2)
        for (int j2 = j1; j2 < n; ++j2)
          if (Sum(i1, j1, i2, j2) == 0)
            dp[i1][j1][i2][j2] = 0;
          else {
            int val = max(i2 - i1 + 1, j2 - j1 + 1);
            for (int i_mid = i1; i_mid < i2; ++i_mid)
              val = min(val, dp[i1][j1][i_mid][j2] + dp[i_mid + 1][j1][i2][j2]);
            for (int j_mid = j1; j_mid < j2; ++j_mid)
              val = min(val, dp[i1][j1][i2][j_mid] + dp[i1][j_mid + 1][i2][j2]);
            dp[i1][j1][i2][j2] = val;
          }
  printf("%d\n", dp[0][0][n - 1][n - 1]);
  return 0;
}
