#include <bits/stdc++.h>
using namespace std;
const int Max = 1231;
const int def = 0x3f3f3f3f;
int dp[60][60][60][60];
char mapp[60][60];
int qian[60][60];
int getval(int x, int y, int xx, int yy) {
  if (xx < x) swap(xx, x);
  if (yy < y) swap(y, yy);
  return qian[xx][yy] - qian[x - 1][yy] - qian[xx][y - 1] + qian[x - 1][y - 1];
}
int dfs(int x, int y, int xx, int yy) {
  int lenx = abs(xx - x + 1);
  int leny = abs(yy - y + 1);
  if (dp[x][y][xx][yy] != -1) return dp[x][y][xx][yy];
  if (getval(x, y, xx, yy) == lenx * leny) {
    dp[x][y][xx][yy] = max(lenx, leny);
    return dp[x][y][xx][yy];
  }
  if (getval(x, y, xx, yy) == 0) {
    dp[x][y][xx][yy] = 0;
    return dp[x][y][xx][yy];
  }
  dp[x][y][xx][yy] = max(lenx, leny);
  for (int i = x; i < xx; i++) {
    dp[x][y][xx][yy] =
        min(dp[x][y][xx][yy], dfs(x, y, i, yy) + dfs(i + 1, y, xx, yy));
  }
  for (int i = y; i < yy; i++) {
    dp[x][y][xx][yy] =
        min(dp[x][y][xx][yy], dfs(x, y, xx, i) + dfs(x, i + 1, xx, yy));
  }
  return dp[x][y][xx][yy];
}
int main() {
  int i, j, h;
  int n, m;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%s", mapp[i] + 1);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      qian[i][j] = qian[i - 1][j] + qian[i][j - 1] - qian[i - 1][j - 1] +
                   (mapp[i][j] == '#');
    }
  memset(dp, -1, sizeof(dp));
  dfs(1, 1, n, n);
  printf("%d\n", dp[1][1][n][n]);
}
