#include <bits/stdc++.h>
using namespace std;
int n, dp[55][55][55][55];
char a[55][55];
bool wh[55][55][55][55], ch[55][55][55][55];
int solve(int u, int d, int l, int r) {
  if (d < u || r < l) return 0;
  if (ch[u][d][l][r]) return dp[u][d][l][r];
  ch[u][d][l][r] = 1;
  dp[u][d][l][r] = max(d - u + 1, r - l + 1);
  for (int i = u; i <= d; i++)
    if (wh[i][l][i][r])
      dp[u][d][l][r] =
          min(dp[u][d][l][r], solve(u, i - 1, l, r) + solve(i + 1, d, l, r));
  for (int j = l; j <= r; j++)
    if (wh[u][j][d][j])
      dp[u][d][l][r] =
          min(dp[u][d][l][r], solve(u, d, l, j - 1) + solve(u, d, j + 1, r));
  return dp[u][d][l][r];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf(" %s", a[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      for (int d = i; d < n; d++) {
        if (a[d][j] == '#') break;
        wh[i][j][d][j] = 1;
      }
      for (int r = j; r < n; r++) {
        if (a[i][r] == '#') break;
        wh[i][j][i][r] = 1;
      }
    }
  printf("%d\n", solve(0, n - 1, 0, n - 1));
  return 0;
}
