#include <bits/stdc++.h>
using namespace std;
int n;
char mat[51][51];
int dp[51][51][51][51];
bool visit[51][51][51][51];
void funct(int x1, int y1, int x2, int y2) {
  if (x1 == x2 and y1 == y2) {
    if (mat[x1][y1] == '#') {
      dp[x1][y1][x2][y2] = 1;
      return;
    }
    dp[x1][y1][x2][y2] = 0;
    return;
  }
  if (visit[x1][y1][x2][y2]) {
    return;
  }
  visit[x1][y1][x2][y2] = 1;
  int cost = max((x2 - x1 + 1), (y2 - y1 + 1));
  for (int i = y1; i < y2; ++i) {
    funct(x1, y1, x2, i);
    funct(x1, i + 1, x2, y2);
    cost = min(cost, dp[x1][y1][x2][i] + dp[x1][i + 1][x2][y2]);
  }
  for (int i = x1; i < x2; ++i) {
    funct(x1, y1, i, y2);
    funct(i + 1, y1, x2, y2);
    cost = min(cost, dp[x1][y1][i][y2] + dp[i + 1][y1][x2][y2]);
  }
  dp[x1][y1][x2][y2] = cost;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", mat[i]);
  }
  funct(0, 0, n - 1, n - 1);
  cout << dp[0][0][n - 1][n - 1];
}
