#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int n;
bool blocked[50][50];
int dp[50][50][50][50];
int pref[50][50];
int sum(int rlo, int clo, int rhi, int chi) {
  int res = pref[rhi][chi];
  if (rlo) res -= pref[rlo - 1][chi];
  if (clo) res -= pref[rhi][clo - 1];
  if (rlo && clo) res += pref[rlo - 1][clo - 1];
  return res;
}
bool isempty(int rlo, int clo, int rhi, int chi) {
  return sum(rlo, clo, rhi, chi) == 0;
}
int get(int rlo, int clo, int rhi, int chi) {
  if (rlo > rhi || clo > chi) return 0;
  return dp[rlo][clo][rhi][chi];
}
void upd(int& a, int b) { a = min(a, b); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++) {
      char c;
      cin >> c;
      blocked[i][j] = (c == '#');
    }
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++) {
      pref[i][j] = blocked[i][j];
      if (i) pref[i][j] += pref[i - 1][j];
      if (j) pref[i][j] += pref[i][j - 1];
      if (i && j) pref[i][j] -= pref[i - 1][j - 1];
    }
  for (int w = (1); w < (n + 1); w++)
    for (int h = (1); h < (n + 1); h++) {
      for (int rlo = 0; rlo < (n - h + 1); rlo++)
        for (int clo = 0; clo < (n - w + 1); clo++) {
          int rhi = rlo + h - 1;
          int chi = clo + w - 1;
          dp[rlo][clo][rhi][chi] = max(w, h);
          for (int rmid = (rlo); rmid < (rhi + 1); rmid++)
            if (isempty(rmid, clo, rmid, chi))
              upd(dp[rlo][clo][rhi][chi],
                  get(rlo, clo, rmid - 1, chi) + get(rmid + 1, clo, rhi, chi));
          for (int cmid = (clo); cmid < (chi + 1); cmid++)
            if (isempty(rlo, cmid, rhi, cmid))
              upd(dp[rlo][clo][rhi][chi],
                  get(rlo, clo, rhi, cmid - 1) + get(rlo, cmid + 1, rhi, chi));
        }
    }
  cout << dp[0][0][n - 1][n - 1];
}
