#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e17;
mt19937 random1(136786931);
int randlr(int l, int r) { return random1() % (r - l + 1) + l; }
const long double PI = 3.1415926535897932384626433832795028841971;
struct Point {
  int first, second;
  Point(){};
  Point(int _x, int _y) {
    first = _x;
    second = _y;
  }
};
struct Vector {
  int first, second;
  Vector(){};
  Vector(Point p) {
    first = p.first;
    second = p.second;
  }
  Vector(Point p1, Point p2) {
    first = p2.first - p1.first;
    second = p2.second - p1.second;
  }
  int operator*(Vector &oth) { return first * oth.second - second * oth.first; }
};
bool in_ang(Point p, Point a, Point o, Point b) {
  Vector oa(o, a), ob(o, b), op(o, p);
  return (oa * op > 0 && op * ob > 0) || (oa * op < 0 && op * ob < 0);
}
const long double eps = 1e-7;
bool eq(long double first, long double second) {
  return abs(first - second) <= eps;
}
const int mod = (1e9) + 7;
vector<vector<int>> mult_matr(vector<vector<int>> a, vector<vector<int>> b) {
  int n = a.size();
  vector<vector<int>> c(n);
  for (int i = 0; i < n; i++) {
    c[i].resize(b[0].size());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < b.size(); j++) {
      for (int k = 0; k < b.size(); k++) {
        c[i][j] += a[i][k] * b[k][j];
        c[i][j] %= (mod - 1);
      }
    }
  }
  return c;
}
vector<vector<int>> fpow(vector<vector<int>> a, int b) {
  vector<vector<int>> answ = a;
  b--;
  while (b) {
    if (b & 1) {
      answ = mult_matr(answ, a);
    }
    a = mult_matr(a, a);
    b >>= 1;
  }
  return answ;
}
int fpow(int first, int second) {
  int answ = 1;
  while (second) {
    if (second & 1) {
      answ *= first;
      answ %= mod;
    }
    first *= first;
    first %= mod;
    second >>= 1;
  }
  return answ;
}
int del(int a, int b) { return (a * fpow(b, mod - 2)) % mod; }
char dp[51][51][51][51];
bool field[51][51];
signed main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      char c;
      cin >> c;
      if (c == '#') field[i][j] = 1;
      dp[i][j][i][j] = field[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int i1 = i; i1 < n; i1++) {
        for (int j1 = j + (i1 == i); j1 < n; j1++) {
          dp[i][j][i1][j1] = max(j1 - j + 1, i1 - i + 1);
        }
      }
    }
  }
  for (int leni = 0; leni < n; leni++) {
    for (int lenj = 0; lenj < n; lenj++) {
      for (int i = 0; i < n - leni; i++) {
        for (int j = 0; j < n - lenj; j++) {
          int i1 = i + leni, j1 = j + lenj;
          for (int k = i; k < i1; k++) {
            dp[i][j][i1][j1] = min((int)dp[i][j][i1][j1],
                                   dp[i][j][k][j1] + dp[k + 1][j][i1][j1]);
          }
          for (int k = j; k < j1; k++) {
            dp[i][j][i1][j1] = min((int)dp[i][j][i1][j1],
                                   dp[i][j][i1][k] + dp[i][k + 1][i1][j1]);
          }
        }
      }
    }
  }
  cout << (int)dp[0][0][n - 1][n - 1];
  return 0;
}
