#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)55;
const int mod = (int)1e9 + 7;
const int P = (int)1e6 + 7;
const int inf = mod;
int n, cnt[maxn][maxn], dp[maxn][maxn][maxn][maxn];
int Cnt(int x1, int x2, int y1, int y2) {
  return cnt[x2][y2] - cnt[x2][y1 - 1] - cnt[x1 - 1][y2] + cnt[x1 - 1][y1 - 1];
}
int calc(int x1, int x2, int y1, int y2) {
  if (Cnt(x1, x2, y1, y2) == (x2 - x1 + 1) * (y2 - y1 + 1)) return 0;
  int &res = dp[x1][x2][y1][y2];
  if (res != -1) return res;
  res = max(x2 - x1, y2 - y1) + 1;
  for (int i = x1; i <= x2 - 1; i++)
    res = min(res, calc(x1, i, y1, y2) + calc(i + 1, x2, y1, y2));
  for (int i = y1; i <= y2 - 1; i++)
    res = min(res, calc(x1, x2, y1, i) + calc(x1, x2, i + 1, y2));
  return res;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      char ch;
      cin >> ch;
      if (i == 1 && j == 1)
        cnt[i][j] = (ch == '.');
      else if (i == 1)
        cnt[i][j] = cnt[i][j - 1] + (ch == '.');
      else if (j == 1)
        cnt[i][j] = cnt[i - 1][j] + (ch == '.');
      else
        cnt[i][j] =
            cnt[i - 1][j] + cnt[i][j - 1] + (ch == '.') - cnt[i - 1][j - 1];
    }
  memset(dp, -1, sizeof(dp));
  cout << calc(1, n, 1, n);
}
