#include <bits/stdc++.h>
using namespace std;
int dp[51][51][51][51];
int sum[51][51];
int matrix[51][51];
void print_2d_matrix(int n, vector<vector<int>> matrix) {
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n; j++) {
      cout << matrix[i][j] << ' ';
    }
    cout << endl;
  }
}
int dfs(int x1, int y1, int x2, int y2) {
  if (dp[x1][y1][x2][y2] > 0) {
    return dp[x1][y1][x2][y2];
  }
  dp[x1][y1][x2][y2] = max(x2 - x1 + 1, y2 - y1 + 1);
  int ts = 0;
  int tx = x1 - 1;
  int ty = y1 - 1;
  ts = sum[x2][y2] - sum[x2][ty] - sum[tx][y2] + sum[tx][ty];
  if (ts == (x2 - x1 + 1) * (y2 - y1 + 1)) {
    return dp[x1][y1][x2][y2];
  } else {
    if (!ts) {
      return dp[x1][y1][x2][y2] = 0;
    }
  }
  for (int i = x1; i < x2; i++) {
    dp[x1][y1][x2][y2] =
        min(dp[x1][y1][x2][y2], dfs(x1, y1, i, y2) + dfs(i + 1, y1, x2, y2));
  }
  for (int i = y1; i < y2; i++) {
    dp[x1][y1][x2][y2] =
        min(dp[x1][y1][x2][y2], dfs(x1, y1, x2, i) + dfs(x1, i + 1, x2, y2));
  }
  return dp[x1][y1][x2][y2];
}
int main() {
  int n;
  char c;
  string s;
  cin >> n;
  vector<string> input_matrix(n);
  memset(dp, -1, sizeof(dp));
  memset(sum, 0, sizeof(sum));
  memset(matrix, 0, sizeof(matrix));
  for (int i = 0; i < n; i++) {
    cin >> s;
    input_matrix[i] = s;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (input_matrix[i][j] == '#') {
        matrix[i][j] = 1;
      } else {
        matrix[i][j] = 0;
      }
      sum[i][j] =
          sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + matrix[i][j];
    }
  }
  int result = dfs(0, 0, n - 1, n - 1);
  cout << result << endl;
  return 0;
}
