#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
int Dp[MAXN][MAXN][MAXN][MAXN];
char Str[MAXN][MAXN];
int n;
int Dfs(int x1, int y1, int x2, int y2);
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) cin >> Str[i][j];
  memset(Dp, -1, sizeof(Dp));
  Dfs(1, 1, n, n);
  cout << Dp[1][1][n][n];
  return 0;
}
int Dfs(int x1, int y1, int x2, int y2) {
  if (Dp[x1][y1][x2][y2] != -1) return Dp[x1][y1][x2][y2];
  if (x1 == x2 && y1 == y2) {
    if (Str[x1][y1] == '#') return 1;
    return 0;
  }
  int ans = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int i = x1; i < x2; i++)
    ans = min(ans, Dfs(x1, y1, i, y2) + Dfs(i + 1, y1, x2, y2));
  for (int i = y1; i < y2; i++)
    ans = min(ans, Dfs(x1, y1, x2, i) + Dfs(x1, i + 1, x2, y2));
  return Dp[x1][y1][x2][y2] = ans;
}
