#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
bool minimize(X &x, const Y &y) {
  X eps = 1e-9;
  if (x > y + eps) {
    x = y;
    return true;
  } else
    return false;
}
template <class X, class Y>
bool maximize(X &x, const Y &y) {
  X eps = 1e-9;
  if (x + eps < y) {
    x = y;
    return true;
  } else
    return false;
}
template <class T>
T Abs(const T &x) {
  return (x < 0 ? -x : x);
}
const int INF = (int)1e9 + 7;
char board[55][55];
int cnt[55][55];
int n;
int f[55][55][55][55];
void init(void) {
  scanf("%d", &n);
  for (int i = (1), _b = (n); i <= _b; i++) scanf("%s", board[i] + 1);
  for (int i = (1), _b = (n); i <= _b; i++)
    for (int j = (1), _b = (n); j <= _b; j++)
      cnt[i][j] = cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1] +
                  (board[i][j] == '#');
}
int getCnt(int x1, int y1, int x2, int y2) {
  if (x1 > x2) return 0;
  if (y1 > y2) return 0;
  return cnt[x2][y2] - cnt[x1 - 1][y2] - cnt[x2][y1 - 1] + cnt[x1 - 1][y1 - 1];
}
int minCost(int x1, int y1, int x2, int y2) {
  if (x1 > x2 || y1 > y2) return 0;
  int &res = f[x1][y1][x2][y2];
  if (res >= 0) return res;
  res = INF;
  minimize(res, getCnt(x1, y1, x2, y2));
  minimize(res, max(x2 - x1, y2 - y1) + 1);
  for (int t = (x1), _b = (x2 - 1); t <= _b; t++)
    minimize(res, minCost(x1, y1, t, y2) + minCost(t + 1, y1, x2, y2));
  for (int t = (y1), _b = (y2 - 1); t <= _b; t++)
    minimize(res, minCost(x1, y1, x2, t) + minCost(x1, t + 1, x2, y2));
  return res;
}
void process(void) {
  memset(f, -1, sizeof f);
  cout << minCost(1, 1, n, n) << endl;
}
int main(void) {
  init();
  process();
  return 0;
}
