#include <bits/stdc++.h>
const int maxn = 55;
using namespace std;
int f[maxn][maxn][maxn][maxn];
int n, sum[maxn][maxn];
string s;
int dp(int x1, int y1, int x2, int y2) {
  if (f[x1][y1][x2][y2] >= 0) return f[x1][y1][x2][y2];
  if (x1 == x2 && y1 == y2) {
    f[x1][y1][x2][y2] = sum[x1][y1];
    return f[x1][y1][x2][y2];
  }
  int ans = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int line = x1; line < x2; line++)
    ans = min(ans, dp(x1, y1, line, y2) + dp(line + 1, y1, x2, y2));
  for (int column = y1; column < y2; column++)
    ans = min(ans, dp(x1, y1, x2, column) + dp(x1, column + 1, x2, y2));
  f[x1][y1][x2][y2] = ans;
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s;
    for (int j = 1; j <= n; j++)
      if (s[j - 1] == '#') sum[i][j] = 1;
  }
  memset(f, -1, sizeof(f));
  printf("%d\n", dp(1, 1, n, n));
  return 0;
}
