#include <bits/stdc++.h>
using namespace std;
const int N = 1e9;
long long n, f[54][54][54][54], ans, t[54][54];
char s[54][54];
long long cal(int i, int j, int u, int v) {
  if (i == u && j == v) return (s[i][j] == '#' ? 1 : 0);
  if (f[i][j][u][v] != -1) return f[i][j][u][v];
  f[i][j][u][v] = max(i - u + 1, j - v + 1);
  if (t[i][j] - t[i][v - 1] - t[u - 1][j] + t[u - 1][v - 1]) {
    for (int k = u; k < i; k++) {
      f[i][j][u][v] = min(f[i][j][u][v], cal(i, j, k + 1, v) + cal(k, j, u, v));
    }
    for (int k = v; k < j; k++) {
      f[i][j][u][v] = min(f[i][j][u][v], cal(i, j, u, k + 1) + cal(i, k, u, v));
    }
  } else
    f[i][j][u][v] = 0;
  return f[i][j][u][v];
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> s[i][j];
      if (s[i][j] == '#')
        t[i][j] = t[i - 1][j] + t[i][j - 1] - t[i - 1][j - 1] + 1;
      else
        t[i][j] = t[i - 1][j] + t[i][j - 1] - t[i - 1][j - 1];
    }
  }
  memset(f, -1, sizeof(f));
  cout << cal(n, n, 1, 1);
}
