#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int up = 20;
const int mod = 1e9 + 7;
vector<pair<int, int> > G[N];
int n, m, c;
char s[55][55];
int a[55][55];
int dp[55][55][55][55];
int get(int x1, int y1, int x2, int y2) {
  return a[x2][y2] - a[x1 - 1][y2] - a[x2][y1 - 1] + a[x1 - 1][y1 - 1];
}
int dfs(int x1, int y1, int x2, int y2) {
  if (dp[x1][y1][x2][y2] != -1) return dp[x1][y1][x2][y2];
  if (x1 == x2 && y1 == y2) {
    return dp[x1][y1][x2][y2] = (s[x1][y1] == '#');
  }
  if (!get(x1, y1, x2, y2)) {
    return dp[x1][y1][x2][y2] = 0;
  }
  dp[x1][y1][x2][y2] = max(x2 - x1 + 1, y2 - y1 + 1);
  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() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    for (int j = 1; j <= n; j++) {
      a[i][j] = (s[i][j] == '#');
      a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
    }
  }
  memset(dp, -1, sizeof(dp));
  printf("%d\n", dfs(1, 1, n, n));
  return 0;
}
