#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
  if (y < x) x = y;
};
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
  if (y > x) x = y;
};
long long gcd(long long x, long long y) { return (y == 0 ? x : gcd(y, x % y)); }
const int MAXN = 3e5 + 100;
const long double PI = acosl(-1.0);
const int N = 55;
int dp[N][N][N][N], n;
bool a[N][N];
int dfs(int x1, int y1, int x2, int y2) {
  if (~dp[x1][y1][x2][y2]) return dp[x1][y1][x2][y2];
  if (x1 == x2 and y1 == y2) return dp[x1][y1][x2][y2] = a[x1][y1];
  int res = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int i = x1; i < x2; i++)
    res = min(res, dfs(x1, y1, i, y2) + dfs(i + 1, y1, x2, y2));
  for (int i = y1; i < y2; i++)
    res = min(res, dfs(x1, y1, x2, i) + dfs(x1, i + 1, x2, y2));
  return dp[x1][y1][x2][y2] = res;
}
void solve() {
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < n + 1; j++) {
      char c;
      cin >> c;
      a[i][j] = (c == '#');
    }
  }
  memset(dp, -1, sizeof(dp));
  cout << dfs(1, 1, n, n) << endl;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
