#include <bits/stdc++.h>
using namespace std;
int board;
char table[55][55];
int sums[55][55];
int sums_cal(int down_row, int down_col, int up_row, int up_col) {
  return sums[up_row][up_col] - sums[up_row][down_col - 1] -
         sums[down_row - 1][up_col] + sums[down_row - 1][down_col - 1];
}
int min_cost[55][55][55][55];
int color[55][55][55][55];
int cal(int down_row, int down_col, int up_row, int up_col) {
  if (!sums_cal(down_row, down_col, up_row, up_col)) return 0;
  if (color[down_row][down_col][up_row][up_col])
    return min_cost[down_row][down_col][up_row][up_col];
  color[down_row][down_col][up_row][up_col] = 1;
  int res = max(up_row - down_row + 1, up_col - down_col + 1);
  for (int i = down_row; i < up_row; i++) {
    int one = cal(down_row, down_col, i, up_col);
    int two = cal(i + 1, down_col, up_row, up_col);
    res = min(res, one + two);
  }
  for (int i = down_col; i < up_col; i++) {
    int one = cal(down_row, down_col, up_row, i);
    int two = cal(down_row, i + 1, up_row, up_col);
    res = min(res, one + two);
  }
  min_cost[down_row][down_col][up_row][up_col] = res;
  return res;
}
void prepare() {
  for (int i = 1; i <= board; i++)
    for (int j = 1; j <= board; j++)
      sums[i][j] = sums[i - 1][j] + sums[i][j - 1] - sums[i - 1][j - 1] +
                   (table[i][j] == '#');
}
void solve() {
  prepare();
  printf("%d", cal(1, 1, board, board));
}
int main() {
  scanf("%d", &board);
  for (int i = 1; i <= board; i++) scanf("%s", table[i] + 1);
  solve();
}
