#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmax(T &i, const T &j) {
  return i < j ? (i = j, 1) : 0;
}
template <typename T>
inline bool chkmin(T &i, const T &j) {
  return i > j ? (i = j, 1) : 0;
}
int n, dp[55][55][55][55];
char s[55][55];
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) scanf("%s", s[i] + 1);
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (n); ++j) dp[i][i][j][j] = (s[i][j] == '#');
  }
  for (int li = (1); li <= (n); ++li) {
    for (int il = 1, ir = li; ir <= n; ++il, ++ir) {
      for (int lj = (1); lj <= (n); ++lj) {
        for (int jl = 1, jr = lj; jr <= n; ++jl, ++jr) {
          int &Dp = dp[il][ir][jl][jr];
          if (ir == il && jr == jl) continue;
          Dp = max(ir - il + 1, jr - jl + 1);
          for (int k = (il); k <= (ir - 1); ++k)
            chkmin(Dp, dp[il][k][jl][jr] + dp[k + 1][ir][jl][jr]);
          for (int k = (jl); k <= (jr - 1); ++k)
            chkmin(Dp, dp[il][ir][jl][k] + dp[il][ir][k + 1][jr]);
        }
      }
    }
  }
  printf("%d\n", dp[1][n][1][n]);
  return 0;
}
