#include <bits/stdc++.h>
using namespace std;
const int maxn = 51;
const int maxm = 400015;
const int inf = 0x3f3f3f3f;
vector<int> ve;
int n, dp[maxn][maxn][maxn][maxn];
char s[maxn][maxn];
int gain(int xl, int yl, int xh, int yh) {
  return max(xh - xl + 1, yh - yl + 1);
}
int dfs(int xl, int yl, int xh, int yh) {
  if (dp[xl][yl][xh][yh] != -1) return dp[xl][yl][xh][yh];
  if (xl == xh && yl == yh) return dp[xl][yl][xh][yh] = (s[xl][yl] == '#');
  int tmp = gain(xl, yl, xh, yh);
  for (int h = 1; h <= xh - xl; h++) {
    tmp = min(tmp, dfs(xl, yl, xl + h - 1, yh) + dfs(xl + h, yl, xh, yh));
  }
  for (int w = 1; w <= yh - yl; w++) {
    tmp = min(tmp, dfs(xl, yl, xh, yl + w - 1) + dfs(xl, yl + w, xh, yh));
  }
  return dp[xl][yl][xh][yh] = tmp;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%d", &n);
  for (int i = (int)1; i <= (int)n; i++) scanf("%s", s[i] + 1);
  printf("%d\n", dfs(1, 1, n, n));
  return 0;
}
