#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int ret = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    ret = ret * 10 + c - 48;
    c = getchar();
  }
  if (f) return -ret;
  return ret;
}
char a[1010][1010];
int n, v[52][52][52][52], f[52][52][52][52], c[101][101], b[101][101];
int solve(int l1, int r1, int l2, int r2) {
  if (l1 > l2 || r1 > r2) return 0;
  int now = 1e9;
  if (v[l1][r1][l2][r2]) return f[l1][r1][l2][r2];
  f[l1][r1][l2][r2] = max(l2 - l1 + 1, r2 - r1 + 1);
  now = f[l1][r1][l2][r2];
  v[l1][r1][l2][r2] = 1;
  for (int i = l1; i <= l2; i++)
    if (c[i][r2] == c[i][r1 - 1])
      now = min(now, solve(l1, r1, i - 1, r2) + solve(i + 1, r1, l2, r2));
  for (int i = r1; i <= r2; i++)
    if (b[l2][i] == b[l1 - 1][i])
      now = min(now, solve(l1, r1, l2, i - 1) + solve(l1, i + 1, l2, r2));
  return f[l1][r1][l2][r2] = now;
}
signed main() {
  n = read();
  for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) b[i][j] = b[i - 1][j] + (a[i][j] == '#');
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) c[i][j] = c[i][j - 1] + (a[i][j] == '#');
  printf("%d", solve(1, 1, n, n));
}
