#include <bits/stdc++.h>
using namespace std;
vector<vector<vector<vector<int> > > > a;
vector<vector<int> > pre;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  a.assign(n, vector<vector<vector<int> > >(
                  n, vector<vector<int> >(n, vector<int>(n, 0))));
  pre.assign(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    string st;
    cin >> st;
    for (int j = 0; j < n; j++) {
      if (st[j] == '#') {
        a[i][j][i][j] = 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      pre[i][j] = a[i][j][i][j] + (i > 0 ? pre[i - 1][j] : 0) +
                  (j > 0 ? pre[i][j - 1] : 0) -
                  (j > 0 && i > 0 ? pre[i - 1][j - 1] : 0);
    }
  }
  for (int h = 0; h < n; h++) {
    for (int w = 0; w < n; w++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          int i2 = i + h;
          int j2 = j + w;
          if (max(i2, j2) > n - 1) continue;
          a[i][j][i2][j2] = max(w + 1, h + 1);
          if (pre[i2][j2] - (i > 0 ? pre[i - 1][j2] : 0) -
                  (j > 0 ? pre[i2][j - 1] : 0) +
                  (j > 0 && i > 0 ? pre[i - 1][j - 1] : 0) ==
              0) {
            a[i][j][i2][j2] = 0;
            continue;
          }
          for (int k = 1; k <= w; k++) {
            if (a[i][j][i2][j2] >
                a[i][j][i2][j2 - k] + a[i][j2 - k + 1][i2][j2])
              a[i][j][i2][j2] = a[i][j][i2][j2 - k] + a[i][j2 - k + 1][i2][j2];
          }
          for (int k = 1; k <= h; k++) {
            if (a[i][j][i2][j2] >
                a[i][j][i2 - k][j2] + a[i2 - k + 1][j][i2][j2])
              a[i][j][i2][j2] = a[i][j][i2 - k][j2] + a[i2 - k + 1][j][i2][j2];
          }
        }
      }
    }
  }
  cout << a[0][0][n - 1][n - 1];
}
