#include <bits/stdc++.h>
using i8 = char;
using u8 = unsigned char;
using i16 = short int;
using u16 = unsigned short int;
using i32 = int;
using u32 = unsigned int;
using i64 = long long int;
using u64 = unsigned long long int;
using f32 = float;
using f64 = double;
using f80 = long double;
const i64 MOD = 1000000007;
const f64 EPS = 1e-9;
inline i64 fast_pow(i64 a, i64 b) {
  i64 ans = 1, base = a;
  while (b) {
    if (b & 1) {
      ans = (ans * base) % MOD;
    }
    base = (base * base) % MOD;
    b >>= 1;
  }
  return ans;
}
using namespace std;
i64 dp[50][50][50][50];
string m[50];
i64 rec(i64 x1, i64 y1, i64 x2, i64 y2) {
  if (dp[x1][y1][x2][y2] != -1) {
    return dp[x1][y1][x2][y2];
  }
  if (x1 == x2 && y1 == y2) {
    return dp[x1][y1][x2][y2] = (m[x1][y1] == '#' ? 1 : 0);
  }
  i64 res = max(x2 - x1 + 1, y2 - y1 + 1);
  for (i64 i = x1; i < x2; ++i) {
    i64 res_left = rec(x1, y1, i, y2);
    i64 res_right = rec(i + 1, y1, x2, y2);
    res = min(res, res_left + res_right);
  }
  for (i64 i = y1; i < y2; ++i) {
    i64 res_up = rec(x1, y1, x2, i);
    i64 res_down = rec(x1, i + 1, x2, y2);
    res = min(res, res_up + res_down);
  }
  return dp[x1][y1][x2][y2] = res;
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  i64 n;
  cin >> n;
  for (i64 i = 0; i < n; ++i) {
    cin >> m[i];
  }
  for (i64 i = 0; i < n; ++i)
    for (i64 j = 0; j < n; ++j)
      for (i64 k = 0; k < n; ++k)
        for (i64 l = 0; l < n; ++l) dp[i][j][k][l] = -1;
  cout << rec(0, 0, n - 1, n - 1) << endl;
  return 0;
}
