#include <bits/stdc++.h>
int n;
int tb[51][51][51][51];
char grid[55][55];
int find(int x1, int y1, int x2, int y2) {
  if (tb[x1][y1][x2][y2] != -1) return tb[x1][y1][x2][y2];
  if (x1 == x2 && y1 == y2) {
    if (grid[x1][y1] == '#')
      tb[x1][y1][x2][y2] = 1;
    else
      tb[x1][y1][x2][y2] = 0;
    return tb[x1][y1][x2][y2];
  }
  int value = x2 - x1 + 1 > y2 - y1 + 1 ? x2 - x1 + 1 : y2 - y1 + 1;
  for (int i = x1; i < x2; i++)
    value = value < find(x1, y1, i, y2) + find(i + 1, y1, x2, y2)
                ? value
                : find(x1, y1, i, y2) + find(i + 1, y1, x2, y2);
  for (int i = y1; i < y2; i++)
    value = value < find(x1, y1, x2, i) + find(x1, i + 1, x2, y2)
                ? value
                : find(x1, y1, x2, i) + find(x1, i + 1, x2, y2);
  tb[x1][y1][x2][y2] = value;
  return tb[x1][y1][x2][y2];
}
int main() {
  memset(tb, -1, sizeof(tb));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%s", grid[i]);
  printf("%d\n", find(0, 0, n - 1, n - 1));
  return 0;
}
