#include <bits/stdc++.h>
int dp[50][50][50][50];
short board[50][50];
int main(int argc, char const *argv[]) {
  int n;
  scanf("%d", &n);
  char ch;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      std::cin >> ch;
      if (ch == '#') {
        board[i][j] = 1;
        dp[i][i][j][j] = 1;
      } else {
        board[i][j] = 0;
        dp[i][i][j][j] = 0;
      }
    }
  for (int w = 2; w <= n; w++) {
    for (int h = 1; h <= w; h++) {
      for (int x = 0; x + w <= n; x++) {
        for (int y = 0; y + h <= n; y++) {
          dp[x][x + w - 1][y][y + h - 1] = w;
          for (int subw = 1; subw < w; subw++) {
            dp[x][x + w - 1][y][y + h - 1] =
                std::min(dp[x][x + w - 1][y][y + h - 1],
                         dp[x][x + subw - 1][y][y + h - 1] +
                             dp[x + subw][x + w - 1][y][y + h - 1]);
          }
          if (w == h) continue;
          dp[y][y + h - 1][x][x + w - 1] = w;
          for (int subw = 1; subw < w; subw++) {
            dp[y][y + h - 1][x][x + w - 1] =
                std::min(dp[y][y + h - 1][x][x + w - 1],
                         dp[y][y + h - 1][x][x + subw - 1] +
                             dp[y][y + h - 1][x + subw][x + w - 1]);
          }
        }
      }
    }
  }
  printf("%d", dp[0][n - 1][0][n - 1]);
  return 0;
}
