#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n;
int s[55][55];
int dp[55][55][55][55];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      char x;
      cin >> x;
      s[i][j] = (x == '#');
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      s[i][j] += s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1];
    }
  }
  for (int cd = 1; cd <= n; cd++) {
    for (int cr = 1; cr <= n; cr++) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          int u = i + cd - 1;
          int v = j + cr - 1;
          if (max(u, v) > n) continue;
          if (s[u][v] - s[i - 1][v] - s[u][j - 1] + s[i - 1][j - 1] == 0)
            continue;
          dp[i][j][u][v] = max(cd, cr);
          for (int x = i; x <= u - 1; x++) {
            dp[i][j][u][v] =
                min(dp[i][j][u][v], dp[i][j][x][v] + dp[x + 1][j][u][v]);
          }
          for (int x = j; x <= v - 1; x++) {
            dp[i][j][u][v] =
                min(dp[i][j][u][v], dp[i][j][u][x] + dp[i][x + 1][u][v]);
          }
        }
      }
    }
  }
  cout << dp[1][1][n][n];
}
