#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T gi() {
  T f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f * x;
}
const int INF = 0x3f3f3f3f, N = 53, M = N << 1;
int n;
char s[N][N];
int dp[N][N][N][N];
int main() {
  n = gi<int>();
  for (int i = 1; i <= n; i += 1) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i += 1)
    for (int j = 1; j <= n; j += 1)
      if (s[i][j] == '.')
        dp[i][j][i][j] = 0;
      else
        dp[i][j][i][j] = 1;
  for (int lenx = 1; lenx <= n; lenx += 1)
    for (int leny = 1 + (lenx == 1); leny <= n; leny += 1)
      for (int x = 1; x + lenx - 1 <= n; x += 1)
        for (int y = 1; y + leny - 1 <= n; y += 1) {
          int xx = x + lenx - 1, yy = y + leny - 1;
          dp[x][y][xx][yy] = max(xx - x + 1, yy - y + 1);
          for (int k = x; k < xx; k += 1)
            dp[x][y][xx][yy] =
                min(dp[x][y][xx][yy], dp[x][y][k][yy] + dp[k + 1][y][xx][yy]);
          for (int k = y; k < yy; k += 1)
            dp[x][y][xx][yy] =
                min(dp[x][y][xx][yy], dp[x][y][xx][k] + dp[x][k + 1][xx][yy]);
        }
  printf("%d\n", dp[1][1][n][n]);
  return 0;
}
