#include <bits/stdc++.h>
using namespace std;
char grid[55][55];
int dp[55][55][55][55];
int gogo(int xL, int xR, int yL, int yR) {
  int &now = dp[xL][xR][yL][yR];
  if (now != -1) {
    return (now);
  }
  now = max(yR - yL + 1, xR - xL + 1);
  for (int i = xL; i < xR; ++i) {
    now = min(now, gogo(xL, i, yL, yR) + gogo(i + 1, xR, yL, yR));
  }
  for (int i = yL; i < yR; ++i) {
    now = min(now, gogo(xL, xR, yL, i) + gogo(xL, xR, i + 1, yR));
  }
  return (now);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", grid[i] + 1);
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      dp[i][i][j][j] = (grid[i][j] == '#');
    }
  }
  printf("%d\n", gogo(1, n, 1, n));
  return (0);
}
