#include <bits/stdc++.h>
using namespace std;
const int N = 50 + 5;
int n, mem[N][N][N][N];
char str[N][N];
int solve(int r0, int c0, int r1, int c1) {
  if (r0 == r1 && c0 == c1) return str[r0][c0] == '#';
  int ret = mem[r0][c0][r1][c1];
  if (ret != -1) return ret;
  ret = max(r1 - r0 + 1, c1 - c0 + 1);
  for (int i = r0; i < r1; ++i)
    ret = min(ret, solve(r0, c0, i, c1) + solve(i + 1, c0, r1, c1));
  for (int i = c0; i < c1; ++i)
    ret = min(ret, solve(r0, c0, r1, i) + solve(r0, i + 1, r1, c1));
  return mem[r0][c0][r1][c1] = ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%s", str[i]);
  memset(mem, -1, sizeof mem);
  printf("%d\n", solve(0, 0, n - 1, n - 1));
  return 0;
}
