#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ii = long long;
using pi = pair<int, int>;
int n;
int dp[51][51][51][51];
char p[51][51][51][51];
int s[51][51];
int getsum(int a, int b, int c, int d) {
  return s[c][d] - s[c][b - 1] - s[a - 1][d] + s[a - 1][b - 1];
}
int hae(int a, int b, int c, int d) {
  if (p[a][b][c][d]) {
    return dp[a][b][c][d];
  }
  p[a][b][c][d] = 1;
  int res = 1e9;
  if (getsum(a, b, c, d) == 0) {
    dp[a][b][c][d] = 0;
    return 0;
  } else {
    res = max(c - a + 1, d - b + 1);
  }
  for (int i = a; i < c; ++i) {
    res = min(res, hae(a, b, i, d) + hae(i + 1, b, c, d));
  }
  for (int j = b; j < d; ++j) {
    res = min(res, hae(a, b, c, j) + hae(a, j + 1, c, d));
  }
  dp[a][b][c][d] = res;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      char c;
      cin >> c;
      s[i][j] = c == '#';
      s[i][j] += s[i - 1][j];
      s[i][j] += s[i][j - 1];
      s[i][j] -= s[i - 1][j - 1];
    }
  }
  cout << hae(1, 1, n, n) << "\n";
}
