#include <bits/stdc++.h>
using namespace std;
struct triplet {
  int a, p, x;
};
int find(vector<vector<int>> &A, vector<vector<int>> &B,
         vector<vector<int>> &grid, int ****dp, int i, int j, int k, int l) {
  if (i > k || j > l) return 0;
  if (i == k && j == l) return grid[i][j];
  if (dp[i][j][k][l] != -1) return dp[i][j][k][l];
  dp[i][j][k][l] = max(k - i + 1, l - j + 1);
  int flag = 0;
  for (int p = i; p <= k; p++) {
    if (A[p][l] - A[p][j] + grid[p][j] > 0) flag = 1;
  }
  if (flag == 0) {
    dp[i][j][k][l] = 0;
    return 0;
  }
  if (k - i + 1 >= l - j + 1) {
    for (int p = i; p <= k; p++) {
      if (A[p][l] - A[p][j] + grid[p][j] == 0) {
        dp[i][j][k][l] =
            min(dp[i][j][k][l], find(A, B, grid, dp, i, j, p - 1, l) +
                                    find(A, B, grid, dp, p + 1, j, k, l));
      }
    }
  } else {
    for (int q = j; q <= l; q++) {
      if (B[k][q] - B[i][q] + grid[i][q] == 0) {
        dp[i][j][k][l] =
            min(dp[i][j][k][l], find(A, B, grid, dp, i, j, k, q - 1) +
                                    find(A, B, grid, dp, i, q + 1, k, l));
      }
    }
  }
  return dp[i][j][k][l];
}
int main() {
  int n;
  cin >> n;
  vector<vector<int>> grid(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      grid[i][j] = (s[j] == '#') ? 1 : 0;
    }
  }
  int ****dp = new int ***[n];
  for (int i = 0; i < n; i++) {
    dp[i] = new int **[n];
    for (int j = 0; j < n; j++) {
      dp[i][j] = new int *[n];
      for (int k = 0; k < n; k++) {
        dp[i][j][k] = new int[n];
        for (int l = 0; l < n; l++) {
          dp[i][j][k][l] = -1;
        }
      }
    }
  }
  vector<vector<int>> A(n, vector<int>(n, 0));
  vector<vector<int>> B(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j == 0)
        A[i][j] = grid[i][j];
      else
        A[i][j] = grid[i][j] + A[i][j - 1];
    }
  }
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < n; i++) {
      if (i == 0)
        B[i][j] = grid[i][j];
      else
        B[i][j] = grid[i][j] + B[i - 1][j];
    }
  }
  cout << find(A, B, grid, dp, 0, 0, n - 1, n - 1);
  return 0;
}
