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