#include <bits/stdc++.h>
using namespace std;
int n;
int row[55][55], col[55][55];
int dp[55][55][55][55];
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      char c;
      cin >> c;
      col[i][j] = col[i - 1][j] + (int)(c == '#');
      row[i][j] = row[i][j - 1] + (int)(c == '#');
    }
  }
  for (int lc = n; lc >= 1; --lc) {
    for (int rc = lc; rc <= n; ++rc) {
      for (int lr = n; lr >= 1; --lr) {
        for (int rr = lr; rr <= n; ++rr) {
          int &res = dp[lc][rc][lr][rr];
          res = max(rc - lc + 1, rr - lr + 1);
          for (int k = lc; k <= rc; ++k)
            if (col[rr][k] - col[lr - 1][k] == 0)
              res = min(res, dp[lc][k - 1][lr][rr] + dp[k + 1][rc][lr][rr]);
          for (int k = lr; k <= rr; ++k)
            if (row[k][rc] - row[k][lc - 1] == 0)
              res = min(res, dp[lc][rc][lr][k - 1] + dp[lc][rc][k + 1][rr]);
        }
      }
    }
  }
  cout << dp[1][n][1][n] << "\n";
  return 0;
}
