#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int dp[N][N][N][N];
char s[N][N];
int dfs(int a, int b, int x, int y) {
  if (a == x && b == y) return s[a][b] == '#';
  if (dp[a][b][x][y] != -1) return dp[a][b][x][y];
  dp[a][b][x][y] = max(x - a + 1, y - b + 1);
  for (int i = a; i <= x - 1; i++)
    dp[a][b][x][y] = min(dp[a][b][x][y], dfs(a, b, i, y) + dfs(i + 1, b, x, y));
  for (int i = b; i <= y - 1; i++)
    dp[a][b][x][y] = min(dp[a][b][x][y], dfs(a, b, x, i) + dfs(a, i + 1, x, y));
  return dp[a][b][x][y];
}
int main() {
  int n;
  memset(dp, -1, sizeof(dp));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  printf("%d\n", dfs(1, 1, n, n));
  return 0;
}
