#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return l + rng() % (r - l + 1); }
const int N = 55;
int n;
int f[N][N][N][N], d[N][N], a[N][N];
int tot(int x, int y, int u, int v) {
  return d[u][v] - d[x - 1][v] - d[u][y - 1] + d[x - 1][y - 1];
}
int F(int x, int y, int u, int v) {
  if (!tot(x, y, u, v)) return 0;
  int &re = f[x][y][u][v];
  if (re != -1) return re;
  re = tot(x, y, u, v) > 0 ? max(u - x, v - y) + 1 : 0;
  if (re == 0) return re;
  for (int i = x; i <= u - 1; ++i) {
    re = min(re, F(x, y, i, v) + F(i + 1, y, u, v));
  }
  for (int j = y; j <= v - 1; ++j) {
    re = min(re, F(x, y, u, j) + F(x, j + 1, u, v));
  }
  return re;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  memset(f, -1, sizeof(f));
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      char x;
      cin >> x;
      a[i][j] = (x == '#');
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      d[i][j] = d[i - 1][j] + d[i][j - 1] + a[i][j] - d[i - 1][j - 1];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      f[i][j][i][j] = a[i][j];
    }
  cout << F(1, 1, n, n);
}
