#include <bits/stdc++.h>
using namespace std;
const int N = 1e6, inf = 1e9, mod = 1e9 + 7;
int n, dp[51][51][51][51];
string s[55];
int ans(int a, int b, int c, int d) {
  if (a == c && b == d) return s[a][b] == '#' ? 1 : 0;
  int &ret = dp[a][b][c][d];
  if (ret != -1) return ret;
  ret = max(c - a + 1, d - b + 1);
  for (int i = a; i < c; i++)
    ret = min(ret, ans(a, b, i, d) + ans(i + 1, b, c, d));
  for (int i = b; i < d; i++)
    ret = min(ret, ans(a, b, c, i) + ans(a, i + 1, c, d));
  return ret;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  cout << ans(0, 0, n - 1, n - 1);
}
