#include <bits/stdc++.h>
using namespace std;
const int N = 55;
char mp[N][N];
int dp[N][N][N][N];
int solve(int x, int y, int u, int v) {
  int &w = dp[x][y][u][v];
  if (w != -1) return w;
  w = max(y - x + 1, v - u + 1);
  for (int i = x; i < y; i++)
    w = min(w, solve(x, i, u, v) + solve(i + 1, y, u, v));
  for (int i = u; i < v; i++)
    w = min(w, solve(x, y, u, i) + solve(x, y, i + 1, v));
  return w;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%s", mp[i] + 1);
    for (int j = 1; j <= n; j++) dp[i][i][j][j] = mp[i][j] == '#';
  }
  printf("%d", solve(1, n, 1, n));
  return 0;
}
