#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
inline void chkmin(T1 &x, T2 y) {
  if (y < x) x = y;
}
template <class T1, class T2>
inline void chkmax(T1 &x, T2 y) {
  if (y > x) x = y;
}
const int BUF_SIZE = 1 << 20;
char buf[BUF_SIZE], *P1 = buf, *P2 = buf, obuf[BUF_SIZE], *PO = obuf;
inline char getc() {
  if (P1 == P2) P2 = (P1 = buf) + fread(buf, 1, BUF_SIZE, stdin);
  return P1 == P2 ? EOF : *P1++;
}
inline void read(int &x) {
  register char ch = getc();
  x = 0;
  while (!isdigit(ch)) ch = getc();
  while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getc();
}
inline void flushO() {
  fwrite(obuf, PO - obuf, 1, stdout);
  PO = obuf;
}
inline void putc(char ch) {
  if (PO == obuf + (BUF_SIZE)) flushO();
  *PO++ = ch;
}
inline void prints(char s[]) {
  for (char *ss = s; *ss != '\0'; ss++) putc(*ss);
}
inline void write(long long x) {
  if (x > 9) write(x / 10);
  putc(x % 10 ^ 48);
}
const int N = 55;
int n, f[N][N][N][N], lb[N][N], rb[N][N];
bool g[N][N];
char ch;
int getf(int x1, int y1, int x2, int y2) {
  if (f[x1][y1][x2][y2] == -1) {
    int minx = 0, miny = y2, maxx, maxy = y1;
    for (int i = x1; i <= (x2); i++) {
      if (rb[i][y1] <= y2 || lb[i][y2] >= y1) {
        if (!minx) minx = i;
        maxx = i;
      }
      chkmin(miny, rb[i][y1]);
      chkmax(maxy, lb[i][y2]);
    }
    f[x1][y1][x2][y2] = max(maxx - minx + 1, maxy - miny + 1);
    for (int i = minx; i <= (maxx - 1); i++)
      chkmin(f[x1][y1][x2][y2], getf(x1, y1, i, y2) + getf(i + 1, y1, x2, y2));
    for (int i = miny; i <= (maxy - 1); i++)
      chkmin(f[x1][y1][x2][y2], getf(x1, y1, x2, i) + getf(x1, i + 1, x2, y2));
  }
  return f[x1][y1][x2][y2];
}
int main() {
  scanf("%d", &n);
  bool flag = 1;
  for (int i = 1; i <= (n); i++)
    for (int j = 1; j <= (n); j++) {
      ch = getchar();
      while (isspace(ch)) ch = getchar();
      g[i][j] = ch == '#';
      if (g[i][j]) flag = 0;
    }
  if (flag) {
    printf("0");
    return 0;
  }
  for (int i = 1; i <= (n); i++) {
    for (int j = 1; j <= (n); j++) lb[i][j] = g[i][j] ? j : lb[i][j - 1];
    rb[i][n + 1] = n + 1;
    for (int j = n; j >= (1); j--) rb[i][j] = g[i][j] ? j : rb[i][j + 1];
  }
  memset(f, -1, sizeof(f));
  printf("%d", getf(1, 1, n, n));
}
