#include <bits/stdc++.h>
using namespace std;
int dp[51][51][51][51];
int pre[51][51];
bool check(int a, int b, int c, int d) {
  int k = pre[c][d] - (pre[a - 1][d] + pre[c][b - 1] - pre[a - 1][b - 1]);
  if (k == 0) {
    return false;
  }
  return true;
}
int find(int a, int b, int c, int d) {
  if (dp[a][b][c][d] != -1) {
    return dp[a][b][c][d];
  }
  if (!check(a, b, c, d)) {
    return 0;
  }
  dp[a][b][c][d] = max(c - a + 1, d - b + 1);
  for (int i = a; i < c; i++) {
    dp[a][b][c][d] =
        min(dp[a][b][c][d], find(a, b, i, d) + find(i + 1, b, c, d));
  }
  for (int i = b; i < d; i++) {
    dp[a][b][c][d] =
        min(dp[a][b][c][d], find(a, b, c, i) + find(a, i + 1, c, d));
  }
  return dp[a][b][c][d];
}
int main() {
  int n;
  cin >> n;
  char mat[n + 1][n + 1];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> mat[i][j];
    }
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      if (i == 0 || j == 0) {
        pre[i][j] = 0;
      } else {
        pre[i][j] = pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1];
        pre[i][j] += mat[i][j] == '#' ? 1 : 0;
      }
    }
  }
  cout << find(1, 1, n, n);
}
