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