#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
int n;
string s;
int dp[52][52][52][52];
int met[52][52][52][52];
int sol(const int& i1, const int& j1, const int& i2, const int& j2) {
  int& w = dp[i1][j1][i2][j2];
  if (met[i1][j1][i2][j2]) return w;
  met[i1][j1][i2][j2] = 1, w = max(i2 - i1 + 1, j2 - j1 + 1);
  for (int k = i1; k < i2; ++k) {
    w = min(w, sol(i1, j1, k, j2) + sol(k + 1, j1, i2, j2));
  }
  for (int k = j1; k < j2; ++k) {
    w = min(w, sol(i1, j1, i2, k) + sol(i1, k + 1, i2, j2));
  }
  return w;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n;
  for (int i = (0); i < (n); ++i) {
    cin >> s;
    for (int j = (0); j < (n); ++j) {
      dp[i][j][i][j] = (s[j] == '#'), met[i][j][i][j] = 1;
    }
  }
  cout << sol(0, 0, n - 1, n - 1);
  return 0;
}
