#include <bits/stdc++.h>
using namespace std;
const int INF = 1e8;
int n, a[55][55], dp[51][51][51][51];
char s[55][55];
inline 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];
}
inline int DP(int x1, int y1, int x2, int y2) {
  if (dp[x1][y1][x2][y2] != INF) return dp[x1][y1][x2][y2];
  for (register int i = x1; i < x2; i++)
    dp[x1][y1][x2][y2] =
        min(dp[x1][y1][x2][y2], DP(x1, y1, i, y2) + DP(i + 1, y1, x2, y2));
  for (register int i = y1; i < y2; i++)
    dp[x1][y1][x2][y2] =
        min(dp[x1][y1][x2][y2], DP(x1, y1, x2, i) + DP(x1, i + 1, x2, y2));
  dp[x1][y1][x2][y2] = min(dp[x1][y1][x2][y2], max(y2 - y1 + 1, x2 - x1 + 1));
  return dp[x1][y1][x2][y2];
}
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (register int i = 1; i <= n; i++)
    for (register int j = 1; j <= n; j++) a[i][j] = s[i][j] == '#';
  for (register int i = 1; i <= n; i++)
    for (register int j = 1; j <= n; j++)
      a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
  for (register int i = 1; i <= n; i++)
    for (register int j = 1; j <= n; j++)
      for (register int k = i; k <= n; k++)
        for (register int p = j; p <= n; p++)
          if (!get(i, j, k, p))
            dp[i][j][k][p] = 0;
          else
            dp[i][j][k][p] = INF;
  printf("%d\n", DP(1, 1, n, n));
  return 0;
}
