#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > mat;
int dp[51][51][51][51];
int sum(int x1, int y1, int x2, int y2) {
  int s = mat[x2][y2];
  if (x1 > 0) s -= mat[x1 - 1][y2];
  if (y1 > 0) s -= mat[x2][y1 - 1];
  if (x1 > 0 and y1 > 0) s += mat[x1 - 1][y1 - 1];
  return s;
}
int solve(int x1, int y1, int x2, int y2) {
  if (x1 > x2 or y1 > y2) return 0;
  if (dp[x1][y1][x2][y2] != -1) return dp[x1][y1][x2][y2];
  int ans = max(x2 - x1 + 1, y2 - y1 + 1);
  if (sum(x1, y1, x2, y2) == 0) ans = 0;
  for (int a = x1; a < x2; a++)
    ans = min(ans, solve(x1, y1, a, y2) + solve(a + 1, y1, x2, y2));
  for (int a = y1; a < y2; a++)
    ans = min(ans, solve(x1, y1, x2, a) + solve(x1, a + 1, x2, y2));
  dp[x1][y1][x2][y2] = ans;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  mat.resize(n, vector<int>(n));
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      char c;
      cin >> c;
      mat[i][j] = c == '#';
      if (i > 0) mat[i][j] += mat[i - 1][j];
      if (j > 0) mat[i][j] += mat[i][j - 1];
      if (i > 0 and j > 0) mat[i][j] -= mat[i - 1][j - 1];
    }
  cout << solve(0, 0, n - 1, n - 1) << endl;
  return 0;
}
