#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int dxx[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
          dyy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long mod = 1000000007;
const int base = 311;
int n;
string s[55];
int dp[55][55][55][55];
int sum[55][55];
int get(int x, int y, int u, int v) {
  return sum[u][v] - sum[x - 1][v] - sum[u][y - 1] + sum[x - 1][y - 1];
}
int solve(int a, int b, int x, int y) {
  if (a > x || b > y) return 0;
  int &res = dp[a][b][x][y];
  if (res != -1) return res;
  res = max(x - a + 1, y - b + 1);
  if (get(a, b, x, y) == 0) return res = 0;
  for (int i = a; i <= x; ++i) {
    res = min(res, solve(a, b, i, y) + solve(i + 1, b, x, y));
  }
  for (int i = b; i <= y; ++i) {
    res = min(res, solve(a, b, x, i) + solve(a, i + 1, x, y));
  }
  return res;
}
void gogo() {
  cin >> n;
  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];
      sum[i][j] += (s[i][j] == '#');
    }
  memset(dp, -1, sizeof(dp));
  cout << solve(1, 1, n, n);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen("sol"
            ".inp",
            "r")) {
    freopen(
        "sol"
        ".inp",
        "r", stdin);
    freopen(
        "sol"
        ".out",
        "w", stdout);
  }
  gogo();
}
