#include <bits/stdc++.h>
int n;
bool mp[54][54];
int sum[54][54];
int dp[54][54][54][54];
void input() {
  scanf("%d", &n);
  char s[54];
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= n; j++) {
      mp[i][j] = (s[j] == '#');
      sum[i][j] =
          sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + (int)mp[i][j];
    }
  }
  memset(dp, -1, sizeof(dp));
}
inline int quesum(int x1, int y1, int x2, int y2) {
  x1--;
  y1--;
  return sum[x2][y2] - sum[x2][y1] - sum[x1][y2] + sum[x1][y1];
}
int calc(int x1, int y1, int x2, int y2) {
  if (~dp[x1][y1][x2][y2]) return dp[x1][y1][x2][y2];
  dp[x1][y1][x2][y2] = std::max(x2 - x1 + 1, y2 - y1 + 1);
  int s = quesum(x1, y1, x2, y2);
  if (s == (x2 - x1 + 1) * (y2 - y1 + 1))
    return dp[x1][y1][x2][y2];
  else if (!s)
    return dp[x1][y1][x2][y2] = 0;
  for (int i = x1; i < x2; i++) {
    dp[x1][y1][x2][y2] = std::min(
        dp[x1][y1][x2][y2], calc(x1, y1, i, y2) + calc(i + 1, y1, x2, y2));
  }
  for (int i = y1; i < y2; i++) {
    dp[x1][y1][x2][y2] = std::min(
        dp[x1][y1][x2][y2], calc(x1, y1, x2, i) + calc(x1, i + 1, x2, y2));
  }
  return dp[x1][y1][x2][y2];
}
int main() {
  input();
  printf("%d\n", calc(1, 1, n, n));
  return 0;
}
