#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool setmin(T &a, T b) {
  if (a > b) return a = b, 1;
  return 0;
}
template <class T>
inline bool setmax(T &a, T b) {
  if (a < b) return a = b, 1;
  return 0;
}
template <class T>
inline T fast(T a, T b, T mod) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T>
inline T russian(T a, T b, T mod) {
  long long res = 0;
  while (b) {
    if (b & 1) res = (res + a) % mod;
    a = (a + a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T>
inline T sub(T a, T b, T mod) {
  return ((a % mod - b % mod) + mod) % mod;
}
template <class T>
inline T add(T a, T b, T mod) {
  return (a % mod + b % mod) % mod;
}
template <class T>
inline T mult(T a, T b, T mod) {
  return ((a % mod * b % mod) + mod) % mod;
}
template <class T>
inline T mult(vector<T> vec, T mod) {
  T ret = 1;
  for (int i = 0; i < (int)(vec).size(); i++) ret = (ret * vec[i]) % mod;
  return ret;
}
template <class T>
istream &operator>>(istream &os, vector<T> &container) {
  for (auto &u : container) os >> u;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &container) {
  for (auto &u : container) os << u << " ";
  return os;
}
template <typename T>
inline T gcd(T a, T b) {
  while (b) swap(a %= b, b);
  return a;
}
long double PI = acos(-1);
long double eps = 1e-11;
const long long T = 1 << 19;
const long long INF = 1e9 + 7;
const long long mod = 998244353;
const long long BIG_INF = 1e18 + 7;
const long long N = 1e6 + 7;
long long n, m, k;
int wyn[55][55][55][55];
char tab[55][55];
int pref[55][55];
int pref2[55][55];
int rec(int a, int b, int c, int d) {
  if (a > c || b > d) return 0;
  if (wyn[a][b][c][d] != -1) return wyn[a][b][c][d];
  int ret = max(c - a + 1, d - b + 1);
  for (int i = a; i <= c; i++)
    if (pref[i][b - 1] == pref[i][d])
      setmin(ret, rec(a, b, i - 1, d) + rec(i + 1, b, c, d));
  for (int j = b; j <= d; j++) {
    if (pref2[a - 1][j] == pref2[c][j])
      setmin(ret, rec(a, b, c, j - 1) + rec(a, j + 1, c, d));
  }
  wyn[a][b][c][d] = ret;
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < (55); i++)
    for (int j = 0; j < (55); j++)
      for (int I = 0; I < (55); I++)
        for (int J = 0; J < (55); J++) wyn[i][j][I][J] = -1;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++) cin >> tab[i + 1][j + 1];
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++)
      pref[i + 1][j + 1] = pref[i + 1][j] + (tab[i + 1][j + 1] == '#');
  for (int j = 0; j < (n); j++)
    for (int i = 0; i < (n); i++)
      pref2[i + 1][j + 1] = pref2[i][j + 1] + (tab[i + 1][j + 1] == '#');
  cout << rec(1, 1, n, n);
}
