#include <bits/stdc++.h>
using namespace std;
long long tt, n, i, j, k, l, m, ma[505], mi, h[505], t[505], no, p, aa, bb, x,
    y, dp[55][55][55][55], d[55][55];
string ans, s;
char c[55][55];
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      cin >> c[i][j];
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      d[i][j] = d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1] + (c[i][j] == '#');
    }
  }
  for (x = 1; x <= n; x++) {
    for (y = 1; y <= n; y++) {
      for (i = 1; i <= n - x + 1; i++) {
        for (j = 1; j <= n - y + 1; j++) {
          int tx = i + x - 1, ty = j + y - 1;
          int t = d[tx][ty] - d[i - 1][ty] - d[tx][j - 1] + d[i - 1][j - 1];
          if (t == 0) {
            dp[i][j][tx][ty] = 0;
            continue;
          } else {
            dp[i][j][tx][ty] = max(x, y);
          }
          for (k = i + 1; k <= tx; k++) {
            dp[i][j][tx][ty] =
                min(dp[i][j][tx][ty], dp[i][j][k - 1][ty] + dp[k][j][tx][ty]);
          }
          for (k = j + 1; k <= ty; k++) {
            dp[i][j][tx][ty] =
                min(dp[i][j][tx][ty], dp[i][j][tx][k - 1] + dp[i][k][tx][ty]);
          }
        }
      }
    }
  }
  cout << dp[1][1][n][n];
}
