#include <bits/stdc++.h>
using namespace std;
const int NMAX = 51;
int n;
int dp[NMAX][NMAX][NMAX][NMAX];
int sum[NMAX][NMAX];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  vector<string> s(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
    s[i] = " " + s[i];
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      sum[i][j] =
          sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + (s[i][j] == '#');
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      for (int ii = i; ii >= 1; --ii)
        for (int jj = j; jj >= 1; --jj) {
          int cnt =
              sum[i][j] - sum[ii - 1][j] - sum[i][jj - 1] + sum[ii - 1][jj - 1];
          if (cnt == 0) continue;
          int cost = max(i - ii + 1, j - jj + 1);
          for (int k = ii; k < i; ++k)
            cost = min(cost, dp[k][j][ii][jj] + dp[i][j][k + 1][jj]);
          for (int k = jj; k < j; ++k)
            cost = min(cost, dp[i][k][ii][jj] + dp[i][j][ii][k + 1]);
          dp[i][j][ii][jj] = cost;
        }
  cout << dp[n][n][1][1] << "\n";
  return 0;
}
