#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y / 2, x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
long long dp[51][51][51][51];
long long n;
char arr[51][51];
long long func(long long a, long long b, long long c, long long d) {
  if (a == c and b == d) {
    return dp[a][b][c][d] = (arr[a][b] == '#');
  }
  long long &ret = dp[a][b][c][d];
  if (ret != -1) return ret;
  long long i;
  ret = max(c - a + 1, d - b + 1);
  for (i = a; i < c; i++)
    ret = min(ret, func(a, b, i, d) + func(i + 1, b, c, d));
  for (i = b; i < d; i++)
    ret = min(ret, func(a, b, c, i) + func(a, i + 1, c, d));
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long i, j;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) cin >> arr[i][j];
  memset(dp, -1, sizeof(dp));
  cout << func(0, 0, n - 1, n - 1);
}
