#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const double Pi = 3.1415926535897932;
const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1};
const int maxn = 50 + 5;
int n;
int f[maxn][maxn][maxn][maxn];
char s[maxn][maxn];
int solve(int a, int b, int c, int d) {
  int &ans = f[a][b][c][d];
  if (a == c && b == d) {
    ans = s[a][b] == '#';
  }
  if (ans != -1) return ans;
  ans = max(c - a + 1, d - b + 1);
  for (int i = a; i < c; i++)
    ans = min(ans, solve(a, b, i, d) + solve(i + 1, b, c, d));
  for (int i = b; i < d; i++)
    ans = min(ans, solve(a, b, c, i) + solve(a, i + 1, c, d));
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  memset(f, -1, sizeof(f));
  printf("%d\n", solve(1, 1, n, n));
  return 0;
}
