#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
struct IO {
  char buf[(1 << 20)], *p1, *p2;
  char pbuf[(1 << 20)], *pp;
  IO() : p1(buf), p2(buf), pp(pbuf) {}
  ~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); }
  inline char gc() {
    if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, (1 << 20), stdin);
    return p1 == p2 ? ' ' : *p1++;
  }
  inline bool blank(char ch) {
    return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
  }
  template <class T>
  inline void read(T &x) {
    double tmp = 1;
    bool sign = 0;
    x = 0;
    char ch = gc();
    for (; !(ch >= '0' && ch <= '9'); ch = gc())
      if (ch == '-') sign = 1;
    for (; (ch >= '0' && ch <= '9'); ch = gc()) x = x * 10 + (ch - '0');
    if (ch == '.')
      for (ch = gc(); (ch >= '0' && ch <= '9'); ch = gc())
        tmp /= 10.0, x += tmp * (ch - '0');
    if (sign) x = -x;
  }
  inline void read(char *s) {
    char ch = gc();
    for (; blank(ch); ch = gc())
      ;
    for (; !blank(ch); ch = gc()) *s++ = ch;
    *s = 0;
  }
  inline void read(char &c) {
    for (c = gc(); blank(c); c = gc())
      ;
  }
  inline void push(const char &c) {
    if (pp - pbuf == (1 << 20)) fwrite(pbuf, 1, (1 << 20), stdout), pp = pbuf;
    *pp++ = c;
  }
  template <class T>
  inline void write(T x) {
    if (x < 0) x = -x, push('-');
    static T sta[35];
    T top = 0;
    do {
      sta[top++] = x % 10, x /= 10;
    } while (x);
    while (top) push(sta[--top] + '0');
  }
  template <class T>
  inline void write(T x, char lastChar) {
    write(x), push(lastChar);
  }
} io;
constexpr long long N = 50 + 5;
constexpr double eps = 1e-6;
long long n;
long long a[N][N];
long long dp[N][N][N][N];
long long sum[N][N];
inline long long getSum(long long r1, long long c1, long long r2,
                        long long c2) {
  return sum[r2][c2] - sum[r1 - 1][c2] - sum[r2][c1 - 1] + sum[r1 - 1][c2 - 1];
}
long long dfs(long long r1, long long c1, long long r2, long long c2) {
  long long &ans = dp[r1][c1][r2][c2];
  if (ans >= 0) return ans;
  long long num = getSum(r1, c1, r2, c2);
  if (num <= 1) return ans = num;
  ans = max((1 + r2 - r1), (1 + c2 - c1));
  for (long long c = c1; c < c2; c++)
    ans = min(ans, dfs(r1, c1, r2, c) + dfs(r1, c + 1, r2, c2));
  for (long long r = r1; r < r2; r++)
    ans = min(ans, dfs(r1, c1, r, c2) + dfs(r + 1, c1, r2, c2));
  return ans;
}
signed main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  ;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      char c;
      cin >> c;
      a[i][j] = (c == '#');
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] + a[i][j] - sum[i - 1][j - 1];
      for (long long k = 1; k <= n; k++)
        for (long long l = 1; l <= n; l++) dp[i][j][k][l] = -1;
    }
  }
  cout << dfs(1, 1, n, n) << endl;
  return 0;
}
