#include <bits/stdc++.h>
using namespace std;
int DP[55][55][55][55] = {0};
bool have[55][55][55][55] = {0};
char all[55][55];
int con[55][55] = {0};
int F(int u, int d, int l, int r) {
  int i;
  if (have[u][d][l][r]) return DP[u][d][l][r];
  if (con[d][r] - con[d][l - 1] - con[u - 1][r] + con[u - 1][l - 1] == 0)
    return 0;
  have[u][d][l][r] = 1;
  DP[u][d][l][r] = max(d - u + 1, r - l + 1);
  for (i = u; i < d; i++)
    DP[u][d][l][r] = min(DP[u][d][l][r], F(u, i, l, r) + F(i + 1, d, l, r));
  for (i = l; i < r; i++)
    DP[u][d][l][r] = min(DP[u][d][l][r], F(u, d, l, i) + F(u, d, i + 1, r));
  return DP[u][d][l][r];
}
int main() {
  int N, i, j;
  scanf("%d", &N);
  for (i = 1; i <= N; i++) {
    scanf("%s", all[i] + 1);
    for (j = 1; j <= N; j++) {
      con[i][j] = con[i - 1][j] + con[i][j - 1] - con[i - 1][j - 1];
      if (all[i][j] == '#') con[i][j]++;
    }
  }
  printf("%d\n", F(1, N, 1, N));
  return 0;
}
