#include <bits/stdc++.h>
using namespace std;
const int N = 51;
int dp[N][N][N][N];
char s[N][N];
int sum[N][N];
int get(int x1, int dfasgeo, int x2, int y2) {
  return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][dfasgeo - 1] +
         sum[x1 - 1][dfasgeo - 1];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> (s[i] + 1);
    for (int j = 1; j <= n; j++) {
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      sum[i][j] += (s[i][j] == '#' ? 1 : 0);
    }
  }
  for (int x1 = n; x1 >= 1; x1--) {
    for (int dfasgeo = n; dfasgeo >= 1; dfasgeo--) {
      for (int x2 = x1; x2 <= n; x2++) {
        for (int y2 = dfasgeo; y2 <= n; y2++) {
          int cnt = get(x1, dfasgeo, x2, y2);
          if (!cnt) {
            continue;
          }
          dp[x1][dfasgeo][x2][y2] = max(x2 - x1 + 1, y2 - dfasgeo + 1);
          for (int i = x1; i < x2; i++) {
            dp[x1][dfasgeo][x2][y2] =
                min(dp[x1][dfasgeo][x2][y2],
                    dp[x1][dfasgeo][i][y2] + dp[i + 1][dfasgeo][x2][y2]);
          }
          for (int i = dfasgeo; i < y2; i++) {
            dp[x1][dfasgeo][x2][y2] =
                min(dp[x1][dfasgeo][x2][y2],
                    dp[x1][dfasgeo][x2][i] + dp[x1][i + 1][x2][y2]);
          }
        }
      }
    }
  }
  cout << dp[1][1][n][n] << '\n';
}
