#include <bits/stdc++.h>
using namespace std;
char board[55][55];
int dp[55][55][55][55];
int solve(int a, int b, int c, int d) {
  if (dp[a][b][c][d] >= 0) return dp[a][b][c][d];
  if (a == c && b == d) return dp[a][b][c][d] = (board[a][b] == '#');
  int maxx = max(c - a + 1, d - b + 1);
  for (int i = a; i < c; i++) {
    maxx = min(maxx, solve(a, b, i, d) + solve(i + 1, b, c, d));
  }
  for (int i = b; i < d; i++) {
    maxx = min(maxx, solve(a, b, c, i) + solve(a, i + 1, c, d));
  }
  return dp[a][b][c][d] = maxx;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; i++) {
    cin >> (board[i] + 1);
  }
  cout << solve(1, 1, n, n);
  return 0;
}
