#include <bits/stdc++.h>
using namespace std;
void io() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
int n;
char s[55][55];
int dp[55][55][55][55];
int f[55][55];
int main() {
  io();
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> (s[i] + 1);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + (s[i][j] == '#');
    }
  }
  for (int x = 1; x <= n; ++x) {
    for (int y = 1; y <= n; ++y) {
      for (int i = 1; i <= n - x + 1; ++i) {
        for (int j = 1; j <= n - y + 1; ++j) {
          int tx = i + x - 1, ty = j + y - 1;
          int t = f[tx][ty] - f[i - 1][ty] - f[tx][j - 1] + f[i - 1][j - 1];
          if (!t) {
            dp[i][j][tx][ty] = 0;
            continue;
          } else
            dp[i][j][tx][ty] = max(x, y);
          for (int 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 (int 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];
}
