#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-18;
const double DEPS = 1e-9;
const long double PI = 3.141592653589793238;
const long long MOD = (long long)(1e9 + 7);
const int N = (int)(3e5) + 10;
void inp() {}
void out() {}
long long gcd(long long fx, long long fy) {
  if (!fy) return fx;
  return gcd(fy, fx % fy);
}
inline void fill(int* ar, int sz, int val) {
  for (int i = 0; i < sz; i++) {
    ar[i] = val;
  }
}
int n, dp[50][50][50][50];
char g[50][50];
int rec(int x, int y, int a, int b) {
  if (x == a && y == b) return g[x][y] == '#';
  int& dp = ::dp[x][y][a][b];
  if (dp != -1) return dp;
  dp = max(a - x, b - y) + 1;
  for (int i = x; i < a; i++) {
    dp = min(dp, rec(i + 1, y, a, b) + rec(x, y, i, b));
  }
  for (int i = y; i < b; i++) {
    dp = min(dp, rec(x, i + 1, a, b) + rec(x, y, a, i));
  }
  return dp;
}
int main() {
  inp();
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf(" %c", &g[i][j]);
    }
  }
  memset(dp, -1, sizeof(dp));
  printf("%d", rec(0, 0, n - 1, n - 1));
}
