#include <bits/stdc++.h>
using namespace std;
const int N = 51;
int dp[N][N][N][N];
string s[N];
int f(int x1, int y1, int x2, int y2) {
  if (x1 == x2 && y1 == y2) {
    if (s[x1][y1] == '#') return 1;
    return 0;
  }
  int &ans = dp[x1][y1][x2][y2];
  int i;
  if (ans != -1) return ans;
  ans = max(x2 - x1 + 1, y2 - y1 + 1);
  for (i = x1; i < x2; i++)
    ans = min(ans, f(x1, y1, i, y2) + f(i + 1, y1, x2, y2));
  for (i = y1; i < y2; i++)
    ans = min(ans, f(x1, y1, x2, i) + f(x1, i + 1, x2, y2));
  return ans;
}
void solve() {
  int n, i;
  cin >> n;
  for (i = 0; i < n; i++) cin >> s[i];
  memset(dp, -1, sizeof dp);
  cout << f(0, 0, n - 1, n - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) solve();
  return 0;
}
