#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int dp[50][50][50][50];
int csum[50][50];
int n;
int arr[N][N];
char str[N][N];
void pre() {
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      sum += arr[i][j];
      csum[i][j] = sum;
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = n - 1; j >= 0; j--) {
      csum[i][j] += csum[i - 1][j];
    }
  }
}
int query(int x1, int y1, int x2, int y2) {
  int ret = csum[x2][y2];
  if (x1 > 0) ret -= csum[x1 - 1][y2];
  if (y1 > 0) ret -= csum[x2][y1 - 1];
  if (x1 > 0 && y1 > 0) ret += csum[x1 - 1][y1 - 1];
  return ret;
}
int rec(int x1, int y1, int x2, int y2) {
  if (query(x1, y1, x2, y2) == 0) return 0;
  int &ret = dp[x1][y1][x2][y2];
  if (ret != -1) return ret;
  ret = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int i = x1; i < x2; i++)
    ret = min(ret, rec(x1, y1, i, y2) + rec(i + 1, y1, x2, y2));
  for (int i = y1; i < y2; i++)
    ret = min(ret, rec(x1, y1, x2, i) + rec(x1, i + 1, x2, y2));
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", str[i]);
    for (int j = 0; j < n; j++) {
      arr[i][j] = (str[i][j] == '#');
    }
  }
  pre();
  memset(dp, -1, sizeof dp);
  printf("%d\n", rec(0, 0, n - 1, n - 1));
}
