#include <bits/stdc++.h>
using namespace std;
int n, a[60][60], sum[60][60], dp[55][55][55][55];
char ch;
int main() {
  int i, j, x1, y1, x2, y2, w, h, suma;
  cin >> n;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      cin >> ch;
      if (ch == '#')
        a[i][j] = 1;
      else
        a[i][j] = 0;
    }
  sum[1][1] = a[1][1];
  for (i = 2; i <= n; i++) sum[1][i] = a[1][i] + sum[1][i - 1];
  for (i = 2; i <= n; i++) sum[i][1] = a[i][1] + sum[i - 1][1];
  for (i = 2; i <= n; i++)
    for (j = 2; j <= n; j++)
      sum[i][j] = a[i][j] + sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1];
  for (w = 1; w <= n; w++)
    for (h = 1; h <= n; h++)
      for (x1 = 1; x1 + w - 1 <= n; x1++)
        for (y1 = 1; y1 + h - 1 <= n; y1++) {
          x2 = x1 + w - 1;
          y2 = y1 + h - 1;
          if ((x1 == x2) && (y1 == y2))
            dp[x1][y1][x2][y2] = a[x1][y1];
          else {
            suma = sum[x2][y2] - sum[x2][y1 - 1] - sum[x1 - 1][y2] +
                   sum[x1 - 1][y1 - 1];
            if (suma == 0) dp[x1][y1][x2][y2] = 0;
            dp[x1][y1][x2][y2] = max(x2 - x1 + 1, y2 - y1 + 1);
            for (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 (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]);
          }
        }
  cout << dp[1][1][n][n];
  return 0;
}
