#include <bits/stdc++.h>
using namespace std;
const int N = 55;
const int oo = 1111111111;
int n, f[N][N][N][N], a[N][N];
int cal(int x1, int y1, int x2, int y2) {
  if (f[x1][y1][x2][y2] != -1) return f[x1][y1][x2][y2];
  if (x2 - x1 == 1 && y2 - y1 == 1) {
    if (a[x1][y1] == 1) {
      f[x1][y1][x2][y2] = 1;
      return 1;
    } else {
      f[x1][y1][x2][y2] = 0;
      return 0;
    }
  }
  f[x1][y1][x2][y2] = max(x2 - x1, y2 - y1);
  for (int i = x1 + 1; i <= x2 - 1; i++) {
    f[x1][y1][x2][y2] =
        min(f[x1][y1][x2][y2], cal(x1, y1, i, y2) + cal(i, y1, x2, y2));
  }
  for (int i = y1 + 1; i <= y2 - 1; i++) {
    f[x1][y1][x2][y2] =
        min(f[x1][y1][x2][y2], cal(x1, y1, x2, i) + cal(x1, i, x2, y2));
  }
  return f[x1][y1][x2][y2];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(f, 255, sizeof(f));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      char h;
      cin >> h;
      if (h == '#')
        a[i][j] = 1;
      else
        a[i][j] = 0;
    }
  }
  cout << cal(1, 1, n + 1, n + 1);
}
