#include <bits/stdc++.h>
using namespace std;
long long dp[55][55][55][55];
long long s[55][55];
long long a[55][55];
long long get(int x1, int y1, int x2, int y2) {
  return s[x1 - 1][y1 - 1] + s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1];
}
int main() {
  int n;
  cin >> n;
  int i, j;
  char c;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      cin >> c;
      a[i][j] = 0;
      if (c == '#') a[i][j] = 1;
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
    }
  }
  int w, h, dx, dy;
  for (w = 0; w < n; w++)
    for (h = 0; h < n; h++)
      for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++) {
          int x = i + w;
          if (x > n) break;
          int y = j + h;
          if (y > n) break;
          dp[i][j][x][y] = max(w, h) + 1;
          if (get(i, j, x, y) == 0) dp[i][j][x][y] = 0;
          for (dx = i; dx < x; dx++)
            dp[i][j][x][y] =
                min(dp[i][j][x][y], dp[i][j][dx][y] + dp[dx + 1][j][x][y]);
          for (dy = j; dy < y; dy++)
            dp[i][j][x][y] =
                min(dp[i][j][x][y], dp[i][j][x][dy] + dp[i][dy + 1][x][y]);
        }
  cout << dp[1][1][n][n];
  return 0;
}
