#include <bits/stdc++.h>
using namespace std;
int f[55][55][55][55], n;
char s[55][55];
int dp(int a, int b, int c, int d) {
  if (f[a][b][c][d] != -1) return f[a][b][c][d];
  if (a == c && b == d) return (s[a][b] == '#');
  int re = max(c - a + 1, d - b + 1);
  for (int i = a; i <= c - 1; i++)
    re = min(re, dp(a, b, i, d) + dp(i + 1, b, c, d));
  for (int i = b; i <= d - 1; i++)
    re = min(re, dp(a, b, c, i) + dp(a, i + 1, c, d));
  return f[a][b][c][d] = re;
}
int main() {
  memset(f, -1, sizeof(f));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  printf("%d", dp(1, 1, n, n));
  return 0;
}
