#include <bits/stdc++.h>
using namespace std;
int n;
char s[55];
int a[55][55];
int sum[55][55];
int f[55][55][55][55];
int dfs(int x, int y, int dx, int dy) {
  if (f[x][y][dx][dy]) return f[x][y][dx][dy];
  if (x == dx && y == dy) return f[x][y][dx][dy] = a[x][y];
  int num = sum[dx][dy] - sum[dx][y - 1] - sum[x - 1][dy] + sum[x - 1][y - 1];
  int cnt = (dx - x + 1) * (dy - y + 1);
  if (num == cnt || num == 0) {
    return f[x][y][dx][dy] = (num == 0 ? 0 : max(dy - y + 1, dx - x + 1));
  }
  f[x][y][dx][dy] = max(dy - y + 1, dx - x + 1);
  int tmp = 55;
  for (int i = x; i < dx; i++) {
    tmp = min(tmp, dfs(x, y, i, dy) + dfs(i + 1, y, dx, dy));
  }
  for (int i = y; i < dy; i++) {
    tmp = min(tmp, dfs(x, y, dx, i) + dfs(x, i + 1, dx, dy));
  }
  return f[x][y][dx][dy] = min(tmp, f[x][y][dx][dy]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= n; j++) a[i][j] = (s[j] == '#');
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
    }
  }
  printf("%d\n", dfs(1, 1, n, n));
  return 0;
}
