#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    ;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
}
const int N = 52, P = 998244353;
int mul(int a, int b) { return 1ll * a * b % P; }
int add(int a, int b) {
  a += b;
  return a >= P ? a - P : a;
}
int sub(int a, int b) {
  a -= b;
  return a < 0 ? a + P : a;
}
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int n, a[N][N], f[N][N][N][N];
char str[N];
int sum(int x1, int y1, int x2, int y2) {
  return a[x2][y2] - a[x1 - 1][y2] - a[x2][y1 - 1] + a[x1 - 1][y1 - 1];
}
int main(int argc, char *argv[]) {
  int n;
  read(n);
  for (int i = 1; i <= (n); ++i) {
    scanf("%s", str);
    for (int j = 1; j <= (n); ++j) a[i][j] = str[j - 1] == '#' ? 1 : 0;
  }
  for (int j = 1; j <= (n); ++j)
    for (int i = 2; i <= (n); ++i) a[i][j] += a[i - 1][j];
  for (int i = 1; i <= (n); ++i)
    for (int j = 2; j <= (n); ++j) a[i][j] += a[i][j - 1];
  for (int dx = 0; dx < (n); ++dx)
    for (int dy = 0; dy < (n); ++dy)
      for (int x1 = 1; x1 <= (n - dx); ++x1)
        for (int y1 = 1; y1 <= (n - dy); ++y1) {
          int x2 = x1 + dx, y2 = y1 + dy;
          f[x1][y1][x2][y2] = max(dx, dy) + 1;
          if (sum(x1, y1, x2, y2) == 0) {
            f[x1][y1][x2][y2] = 0;
          }
          for (int p = 0; p < (dx); ++p)
            (f[x1][y1][x2][y2] >
                     (f[x1][y1][x1 + p][y2] + f[x1 + p + 1][y1][x2][y2])
                 ? f[x1][y1][x2][y2] =
                       (f[x1][y1][x1 + p][y2] + f[x1 + p + 1][y1][x2][y2])
                 : f[x1][y1][x2][y2]);
          for (int p = 0; p < (dy); ++p)
            (f[x1][y1][x2][y2] >
                     (f[x1][y1][x2][y1 + p] + f[x1][y1 + p + 1][x2][y2])
                 ? f[x1][y1][x2][y2] =
                       (f[x1][y1][x2][y1 + p] + f[x1][y1 + p + 1][x2][y2])
                 : f[x1][y1][x2][y2]);
        }
  cout << f[1][1][n][n] << endl;
}
