#include <bits/stdc++.h>
template <class _T>
void r(_T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  x *= f;
}
const int N = 55;
int n;
char str[N][N];
int dp[N][N][N][N];
int Max(int x, int y) { return x > y ? x : y; }
int Min(int x, int y) { return x < y ? x : y; }
int dfs(int a, int b, int c, int d) {
  if (a == c && b == d) return str[a][b] == '#';
  if (dp[a][b][c][d] != -1) return dp[a][b][c][d];
  dp[a][b][c][d] = Max(c - a, d - b) + 1;
  for (int i = a; i < c; i++)
    dp[a][b][c][d] = Min(dp[a][b][c][d], dfs(a, b, i, d) + dfs(i + 1, b, c, d));
  for (int i = b; i < d; i++)
    dp[a][b][c][d] = Min(dp[a][b][c][d], dfs(a, b, c, i) + dfs(a, i + 1, c, d));
  return dp[a][b][c][d];
}
int main() {
  r(n);
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  memset(dp, -1, sizeof dp);
  printf("%d", dfs(1, 1, n, n));
  return 0;
}
