#include <bits/stdc++.h>
using namespace std;
int dp[51][51][51][52];
int a[51][51];
int dfs(int x1, int x2, int y1, int y2) {
  if (dp[x1][x2][y1][y2] != -1) {
    return dp[x1][x2][y1][y2];
  }
  if (x1 == x2 && y1 == y2) {
    return dp[x1][x2][y1][y2] = a[x1][y1];
  }
  dp[x1][x2][y1][y2] = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int i = x1; i < x2; i++) {
    dp[x1][x2][y1][y2] =
        min(dp[x1][x2][y1][y2], dfs(x1, i, y1, y2) + dfs(i + 1, x2, y1, y2));
  }
  for (int i = y1; i < y2; i++) {
    dp[x1][x2][y1][y2] =
        min(dp[x1][x2][y1][y2], dfs(x1, x2, y1, i) + dfs(x1, x2, i + 1, y2));
  }
  return dp[x1][x2][y1][y2];
}
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      char c;
      cin >> c;
      a[i][j] = (c == '#');
    }
  }
  memset(dp, -1, sizeof(dp));
  cout << dfs(1, n, 1, n);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
