#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 9;
const long long inf = 1e18 + 18;
const int max6 = 1e6 + 6;
const int modx = 1e9 + 123;
const int mody = 997;
const int base = 137;
string a[105];
int s[105][105], b[105][105];
int f[55][55][55][55], cl[55][55][55][55];
int sum(int x1, int y1, int x2, int y2) {
  return s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];
}
int cal(int x1, int y1, int x2, int y2) {
  if (cl[x1][y1][x2][y2] == 1) return f[x1][y1][x2][y2];
  cl[x1][y1][x2][y2] = 1;
  int res = max(x2 - x1 + 1, y2 - y1 + 1);
  res = min(res, sum(x1, y1, x2, y2));
  for (int first = x1; first < x2; ++first)
    res = min(res, cal(x1, y1, first, y2) + cal(first + 1, y1, x2, y2));
  for (int second = y1; second < y2; ++second)
    res = min(res, cal(x1, y1, x2, second) + cal(x1, second + 1, x2, y2));
  f[x1][y1][x2][y2] = res;
  return res;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < n; ++j) b[i][j + 1] = a[i][j] == '#';
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + b[i][j];
  cout << cal(1, 1, n, n);
}
