#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3ffffff;
const long long LL_INF = 0x3fffffffffffffffll;
const int MOD = 1e9 + 7;
const long long HASH_KEY = 6151;
const long long HASH_MOD = 1610612741;
const int MAXN = 51;
char s[MAXN][MAXN];
int f[MAXN][MAXN][MAXN][MAXN];
int dfs(int x1, int y1, int x2, int y2) {
  if (x1 == x2 && y1 == y2) {
    return s[x1][y1] == '#' ? 1 : 0;
  }
  if (~f[x1][y1][x2][y2]) {
    return f[x1][y1][x2][y2];
  }
  int &ret = f[x1][y1][x2][y2];
  ret = max(y2 - y1 + 1, x2 - x1 + 1);
  for (int i = int(x1); i < int(x2); ++i) {
    ret = min(ret, dfs(x1, y1, i, y2) + dfs(i + 1, y1, x2, y2));
  }
  for (int i = int(y1); i < int(y2); ++i) {
    ret = min(ret, dfs(x1, y1, x2, i) + dfs(x1, i + 1, x2, y2));
  }
  fprintf(stderr, "%d %d %d %d ret=%d\n", x1, y1, x2, y2, ret);
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = int(0); i < int(n); ++i) {
    cin >> s[i];
  }
  memset(f, -1, sizeof(f));
  cout << dfs(0, 0, n - 1, n - 1) << "\n";
  return 0;
}
