#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
using ll = long long;
using vi = vector<int>;
const int N = 57;
int n;
int dp[N][N][N][N];
vector<vector<int>> a;
int DP(int x1, int x2, int y1, int y2) {
  int& ret = dp[x1][x2][y1][y2];
  if (ret != -1) return ret;
  int t = a[x2][y2] - a[x2][y1 - 1] - a[x1 - 1][y2] + a[x1 - 1][y1 - 1];
  ret = t ? max(x2 - x1 + 1, y2 - y1 + 1) : 0;
  for (int i = x1; i < x2; i++)
    ret = min(ret, DP(x1, i, y1, y2) + DP(i + 1, x2, y1, y2));
  for (int i = y1; i < y2; i++)
    ret = min(ret, DP(x1, x2, y1, i) + DP(x1, x2, i + 1, y2));
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  vector<vector<char>> grid(n + 1, vector<char>(n + 1));
  a = vector<vi>(n + 1, vi(n + 1, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> grid[i][j];
      a[i][j] =
          (grid[i][j] == '#') + a[i][j - 1] + a[i - 1][j] - a[i - 1][j - 1];
    }
  }
  memset(dp, -1, sizeof dp);
  cout << DP(1, n, 1, n) << "\n";
  return 0;
}
