#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const long long INF = 1e18;
const int MAXN = 1e5 + 1;
const double EPS = 1e-6;
int dp[50][50][50][50], s[50][50];
inline int sum(int x1, int y1, int x2, int y2) {
  return s[x2][y2] - (x1 > 0 ? s[x1 - 1][y2] : 0) -
         (y1 > 0 ? s[x2][y1 - 1] : 0) +
         (x1 > 0 and y1 > 0 ? s[x1 - 1][y1 - 1] : 0);
}
int ans(int x1, int y1, int x2, int y2) {
  if (x2 < x1 or y2 < y1) return 0;
  if (dp[x1][y1][x2][y2] >= 0) return dp[x1][y1][x2][y2];
  dp[x1][y1][x2][y2] = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int tx = x1; tx <= x2; tx++) {
    if (sum(tx, y1, tx, y2) == 0)
      dp[x1][y1][x2][y2] = min(dp[x1][y1][x2][y2], ans(x1, y1, tx - 1, y2) +
                                                       ans(tx + 1, y1, x2, y2));
  }
  for (int ty = y1; ty <= y2; ty++) {
    if (sum(x1, ty, x2, ty) == 0)
      dp[x1][y1][x2][y2] = min(dp[x1][y1][x2][y2], ans(x1, y1, x2, ty - 1) +
                                                       ans(x1, ty + 1, x2, y2));
  }
  return dp[x1][y1][x2][y2];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int START_TIME = clock();
  srand(time(0));
  for (int a = 0; a < 50; a++)
    for (int b = 0; b < 50; b++)
      for (int c = 0; c < 50; c++)
        for (int d = 0; d < 50; d++) dp[a][b][c][d] = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      char c;
      cin >> c;
      s[j][i] = -sum(j, i, j, i) + (c != '.');
    }
  }
  cout << ans(0, 0, n - 1, n - 1);
  cerr << '\n' << clock() - START_TIME;
  return 0;
}
