#include <bits/stdc++.h>
using namespace std;
int n, l[55][55][55][55];
int dq(int x, int y, int u, int v) {
  int &tg = l[x][y][u][v];
  if (~tg) return tg;
  tg = max(u - x + 1, v - y + 1);
  for (int i = x; i <= u - 1; ++i)
    tg = min(tg, dq(x, y, i, v) + dq(i + 1, y, u, v));
  for (int i = y; i <= v - 1; ++i)
    tg = min(tg, dq(x, y, u, i) + dq(x, i + 1, u, v));
  return tg;
}
int main() {
  memset(l, -1, sizeof l);
  cin >> n;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      char c;
      cin >> c;
      l[i][j][i][j] = c == '#';
    }
  cout << dq(1, 1, n, n);
}
