#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795l;
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
  return x * x;
}
template <typename T>
inline T abs(T x) {
  return x > T() ? x : -x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool umn(T1& a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int N = 55;
char c[N][N];
int pref[N][N];
bool botva(int i1, int j1, int i2, int j2) {
  ++i2, ++j2;
  return (pref[i2][j2] - pref[i2][j1] - pref[i1][j2] + pref[i1][j1]) == 0;
}
int d[N][N][N][N];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout.setf(ios::showpoint | ios::fixed);
  cout.precision(20);
  int n;
  cin >> n;
  for (int i = int(0); i < int(n); ++i) {
    for (int j = int(0); j < int(n); ++j) {
      cin >> c[i][j];
    }
  }
  memset(pref, 0, sizeof(pref));
  for (int i = int(0); i < int(n); ++i) {
    for (int j = int(0); j < int(n); ++j) {
      int cur = (c[i][j] == '#');
      pref[i + 1][j + 1] = pref[i][j + 1] + pref[i + 1][j] - pref[i][j] + cur;
    }
  }
  for (int leni = int(0); leni < int(n); ++leni) {
    for (int lenj = int(0); lenj < int(n); ++lenj) {
      for (int i = 0; i + leni < n; ++i) {
        for (int j = 0; j + lenj < n; ++j) {
          d[i][j][i + leni][j + lenj] = max(leni, lenj) + 1;
          if (botva(i, j, i + leni, j + lenj)) {
            d[i][j][i + leni][j + lenj] = 0;
          }
          if (leni > lenj) {
            for (int k = i; k < i + leni; ++k) {
              umn(d[i][j][i + leni][j + lenj],
                  d[i][j][k][j + lenj] + d[k + 1][j][i + leni][j + lenj]);
            }
          } else {
            for (int k = j; k < j + lenj; ++k) {
              umn(d[i][j][i + leni][j + lenj],
                  d[i][j][i + leni][k] + d[i][k + 1][i + leni][j + lenj]);
            }
          }
        }
      }
    }
  }
  cout << d[0][0][n - 1][n - 1] << "\n";
  return 0;
}
