#include <bits/stdc++.h>
using namespace std;
int const N = 50;
int dp[N][N][N][N], sm[N + 1][N + 1], n;
char g[N][N + 1];
inline int gtsm(int a, int b, int c, int d) {
  return sm[c + 1][d + 1] - sm[a][d + 1] - sm[c + 1][b] + sm[a][b];
}
inline void up(int &x, int y) {
  if (y < x) x = y;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (int)(n); ++i) scanf("%s", g[i]);
  for (int i = 1; i < (int)(n + 1); ++i)
    for (int j = 1; j < (int)(n + 1); ++j)
      sm[i][j] = (g[i - 1][j - 1] == '#') + sm[i - 1][j] + sm[i][j - 1] -
                 sm[i - 1][j - 1];
  for (int i = 0; i < (int)(n); ++i)
    for (int j = 0; j < (int)(n); ++j)
      for (int k = i; k < (int)(n); ++k)
        for (int w = j; w < (int)(n); ++w)
          dp[i][j][k][w] = gtsm(i, j, k, w) ? max(k - i + 1, w - j + 1) : 0;
  for (int i = n - 1; i >= 0; --i)
    for (int j = n - 1; j >= 0; --j)
      for (int k = i; k < (int)(n); ++k)
        for (int w = j; w < (int)(n); ++w) {
          int &d = dp[i][j][k][w];
          for (int z = i; z < (int)(k); ++z)
            up(d, dp[i][j][z][w] + dp[z + 1][j][k][w]);
          for (int z = j; z < (int)(w); ++z)
            up(d, dp[i][j][k][z] + dp[i][z + 1][k][w]);
        }
  printf("%d\n", dp[0][0][n - 1][n - 1]);
}
