#include <bits/stdc++.h>
using namespace std;
void mincost(int n, int** grid, int**** table) {
  for (int u = 0; u <= n; u++) {
    for (int v = 0; v <= n; v++) {
      for (int i = 0; i <= n - u && i != n; i++) {
        for (int j = 0; j <= n - v && j != n; j++) {
          if (u == 0 || v == 0)
            table[i][j][u][v] = 0;
          else if (u == 1 && v == 1)
            table[i][j][u][v] = grid[i][j];
          else if (table[i][j][u - 1][v - 1] + table[i + u - 1][j][1][v - 1] +
                       table[i][j + v - 1][u - 1][1] +
                       table[i + u - 1][j + v - 1][1][1] ==
                   0) {
            table[i][j][u][v] = 0;
          } else {
            int min = (u > v) ? u : v;
            for (int r = 1; r < u; r++) {
              int value = table[i][j][r][v] + table[i + r][j][u - r][v];
              if (value < min) min = value;
            }
            for (int c = 1; c < v; c++) {
              int value = table[i][j][u][c] + table[i][j + c][u][v - c];
              if (value < min) min = value;
            }
            table[i][j][u][v] = min;
          }
        }
      }
    }
  }
}
int main() {
  int n;
  cin >> n;
  int** grid = new int*[n];
  for (int i = 0; i < n; i++) grid[i] = new int[n];
  int**** table = new int***[n + 1];
  for (int i = 0; i <= n; i++) {
    table[i] = new int**[n + 1];
    for (int j = 0; j <= n; j++) {
      table[i][j] = new int*[n - i + 1];
      for (int k = 0; k <= n - i; k++) {
        table[i][j][k] = new int[n - j + 1];
        for (int l = 0; l <= n - j; l++) table[i][j][k][l] = 0;
      }
    }
  }
  string str;
  getline(cin, str);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    string str;
    getline(cin, str);
    for (int j = 0; j < n; j++) {
      if (str[j] == '#')
        grid[i][j] = 1;
      else if (str[j] == '.')
        grid[i][j] = 0;
      sum += grid[i][j];
    }
  }
  if (sum == 0) {
    cout << 0;
    return 0;
  } else if (sum == n * n) {
    cout << n;
    return 0;
  }
  mincost(n, grid, table);
  cout << table[0][0][n][n];
}
