#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
int n;
char c[MAXN][MAXN];
int sum[MAXN][MAXN];
int dp[MAXN][MAXN][MAXN][MAXN];
int getSum(int xl, int xr, int yl, int yr) {
  int res = sum[xr][yr];
  if (xl > 0) res -= sum[xl - 1][yr];
  if (yl > 0) res -= sum[xr][yl - 1];
  if (xl > 0 && yl > 0) res += sum[xl - 1][yl - 1];
  return res;
}
int calc(int xl, int xr, int yl, int yr) {
  if (xl > xr || yl > yr) return 0;
  int& res = dp[xl][xr][yl][yr];
  if (res != -1) return res;
  res = max(xr - xl + 1, yr - yl + 1);
  if (getSum(xl, xr, yl, yr) == 0) res = 0;
  for (int i = xl; i <= xr; i++)
    if (getSum(i, i, yl, yr) == 0)
      res = min(res, calc(xl, i - 1, yl, yr) + calc(i + 1, xr, yl, yr));
  for (int j = yl; j <= yr; j++)
    if (getSum(xl, xr, j, j) == 0)
      res = min(res, calc(xl, xr, yl, j - 1) + calc(xl, xr, j + 1, yr));
  return res;
}
int main() {
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%c", &c[i][j]);
    }
    scanf("\n");
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (c[i][j] == '#') sum[i][j] = 1;
      if (i > 0) sum[i][j] += sum[i - 1][j];
      if (j > 0) sum[i][j] += sum[i][j - 1];
      if (i > 0 && j > 0) sum[i][j] -= sum[i - 1][j - 1];
    }
  }
  cout << calc(0, n - 1, 0, n - 1) << endl;
  return 0;
}
