#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    que;
stringstream ssin;
const long long LINF = 0x7fffffffffffffffll;
const int N = 55, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
int n, m;
char s[N][N];
int dp[N][N][N][N];
inline long long read() {
  char c = getchar();
  long long x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int dfs(int lx, int ly, int rx, int ry) {
  if (lx == rx && ly == ry) {
    return s[lx][ly] == '#';
  }
  if (dp[lx][ly][rx][ry] != -1) {
    return dp[lx][ly][rx][ry];
  }
  int ans = n;
  ans = max(rx - lx + 1, ry - ly + 1);
  for (int i = lx; i < rx; ++i) {
    ans = min(ans, dfs(lx, ly, i, ry) + dfs(i + 1, ly, rx, ry));
  }
  for (int i = ly; i < ry; ++i) {
    ans = min(ans, dfs(lx, ly, rx, i) + dfs(lx, i + 1, rx, ry));
  }
  dp[lx][ly][rx][ry] = ans;
  return ans;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  memset(dp, -1, sizeof dp);
  ;
  cout << dfs(1, 1, n, n) << '\n';
}
