#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
int dp[maxn][maxn][maxn][maxn];
char G[maxn][maxn];
int n;
inline int Min(int a, int b) { return a > b ? b : a; }
inline int Max(int a, int b) { return a > b ? a : b; }
int DFS(int xl, int xr, int yl, int yr) {
  if (dp[xl][xr][yl][yr] != -1) {
    return dp[xl][xr][yl][yr];
  }
  if (xl == xr and yl == yr) {
    return dp[xl][xr][yl][yr] = (G[xl][yl] == '#');
  }
  int result = Max(xr - xl + 1, yr - yl + 1);
  for (register int i = xl; i < xr; i++)
    result = Min(result, (DFS(xl, i, yl, yr) + DFS(i + 1, xr, yl, yr)));
  for (register int i = yl; i < yr; i++)
    result = Min(result, (DFS(xl, xr, yl, i) + DFS(xl, xr, i + 1, yr)));
  return dp[xl][xr][yl][yr] = result;
}
int main() {
  memset(dp, -1, sizeof(dp));
  ios_base::sync_with_stdio(false);
  cin.tie();
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) cin >> G[i][j];
  cout << DFS(1, n, 1, n);
  return 0;
}
