#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000010;
const int N = 200010;
template <typename T>
inline T sqr(T x) {
  return (x * x);
}
int n;
int d[50 * 50 * 50 * 50];
string s[51];
int index(int x1, int y1, int x2, int y2) {
  return 50 * 50 * 50 * x1 + 50 * 50 * y1 + 50 * x2 + y2;
}
bool isBlack(int x, int y) { return s[y][x] == '#'; }
int calc(int x1, int y1, int x2, int y2) {
  int ind = index(x1, y1, x2, y2);
  if (d[ind] != INF) {
    return d[ind];
  }
  if (x2 == x1) {
    int ans = 0;
    for (int i = y1; i <= y2; i++) {
      if (isBlack(x1, i)) {
        ans++;
      }
    }
    d[ind] = min(d[ind], ans);
    return d[ind];
  }
  if (y2 == y1) {
    int ans = 0;
    for (int i = x1; i <= x2; i++) {
      if (isBlack(i, y1)) {
        ans++;
      }
    }
    d[ind] = min(d[ind], ans);
    return d[ind];
  }
  int ans = d[ind];
  ans = min(ans, max(x2 - x1 + 1, y2 - y1 + 1));
  for (int i = x1; i < x2; i++) {
    ans = min(ans, calc(x1, y1, i, y2) + calc(i + 1, y1, x2, y2));
  }
  for (int i = y1; i < y2; i++) {
    ans = min(ans, calc(x1, y1, x2, i) + calc(x1, i + 1, x2, y2));
  }
  d[ind] = ans;
  return d[ind];
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < 50 * 50 * 50 * 50; i++) {
    d[i] = INF;
  }
  cout << calc(0, 0, n - 1, n - 1);
  return 0;
}
