#include <bits/stdc++.h>
const int M = 51;
char s[M][M];
int n, dp[M][M][M][M];
int Max(const int x, const int y) {
  if (x > y) return x;
  return y;
}
int Min(const int x, const int y) {
  if (x < y) return x;
  return y;
}
int dfs(const int x1, const int y1, const int x2, const int y2) {
  if (~dp[x1][y1][x2][y2]) return dp[x1][y1][x2][y2];
  if (x1 == x2 && y1 == y2) return s[x1][y1] == '#';
  int ans = Max(x2 - x1 + 1, y2 - y1 + 1);
  for (int i = x1; i < x2; ++i)
    ans = Min(ans, dfs(x1, y1, i, y2) + dfs(i + 1, y1, x2, y2));
  for (int i = y1; i < y2; ++i)
    ans = Min(ans, dfs(x1, y1, x2, i) + dfs(x1, i + 1, x2, y2));
  return dp[x1][y1][x2][y2] = ans;
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
  printf("%d", dfs(1, 1, n, n));
  return 0;
}
