#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<db, db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int) (x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define resz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define f1r(i, a, b) for(int i = (a); i < (b); ++i)
#define f0r(i, a) f1r(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto& a : x)

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }

constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1, T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T, SZ>& a);
    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class T, class... Ts> void re(T& t, Ts&... ts) {
        re(t); re(ts...); }
    template<class T> void re(complex<T>& x) { T a, b; re(a, b); x = cd(a, b); }
    template<class T1, class T2> void re(pair<T1, T2>& p) { re(p.f, p.s); }
    template<class T> void re(vector<T>& a) { F0R(i, sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T, SZ>& a) { F0R(i, SZ) re(a[i]); }
}

using namespace input;

namespace output {
    void pr(int x) { cout << x; }
    void pr(long x) { cout << x; }
    void pr(ll x) { cout << x; }
    void pr(unsigned x) { cout << x; }
    void pr(unsigned long x) { cout << x; }
    void pr(unsigned long long x) { cout << x; }
    void pr(float x) { cout << x; }
    void pr(double x) { cout << x; }
    void pr(ld x) { cout << x; }
    void pr(char x) { cout << x; }
    void pr(const char* x) { cout << x; }
    void pr(const string& x) { cout << x; }
    void pr(bool x) { pr(x ? "true" : "false"); }
    template<class T> void pr(const complex<T>& x) { cout << x; }
    template<class T1, class T2> void pr(const pair<T1, T2>& x);
    template<class T> void pr(const T& x);
    template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
        pr(t); pr(ts...); }
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{", x.f, ", ", x.s, "}"); }
    template<class T> void pr(const T& x) {
        pr("{"); // const iterator needed for vector<bool>
        bool fst = 1; for (const auto& a: x) pr(!fst ? ", " : "", a), fst = 0;
        pr("}"); }
    void ps() { pr("\n"); } // print w/ spaces
    template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); }
    void pc() { pr("]\n"); } // debug w/ commas
    template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(), "r", stdin); }
    void setOut(string s) { freopen(s.c_str(), "w", stdout); }
    void setIO(string s = "") {
        cin.sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); }
    }
}

using namespace io;

const int MOD = 1e9 + 7; // 998244353;
const ld PI = acos((ld) -1);

typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator << (ostream& os, const mi& a) { return os << a.val; }
    friend void pr(const mi& a) { pr(a.val); }
    friend void re(mi& a) { ll x; re(x); a = mi(x); }
    friend bool operator == (const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator != (const mi& a, const mi& b) { return !(a == b); }
    friend bool operator < (const mi& a, const mi& b) { return a.val < b.val; }
    friend bool operator > (const mi& a, const mi& b) { return a.val > b.val; }
    friend bool operator <= (const mi& a, const mi& b) { return a.val <= b.val; }
    friend bool operator >= (const mi& a, const mi& b) { return a.val >= b.val; }
    mi operator - () const { return mi(-val); }
    mi& operator += (const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator -= (const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator *= (const mi& m) { val = (ll) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator /= (const mi& m) { return (*this) *= inv(m); }
    friend mi operator + (mi a, const mi& b) { return a += b; }
    friend mi operator - (mi a, const mi& b) { return a -= b; }
    friend mi operator * (mi a, const mi& b) { return a *= b; }
    friend mi operator / (mi a, const mi& b) { return a /= b; }
};

typedef pair<mi, mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;
const int LOG = 30;
const int MAX = (2e5+5)*30;
struct node {
    int go[LOG+2];
    int num;
    node() {
        for (int i = 0; i < LOG+2; i++) go[i] = MAX-1;
        num = 0;
    }
};
node dat[MAX];
int cur = 1;
void ins(int x) {
    int at = 0;
    dat[at].num++;
    int to = bits(x)+1;
    if (x == 0) to = 0;
    if (dat[at].go[to] == MAX-1) {
        dat[at].go[to] = cur++;
    }
    at = dat[at].go[to];
    if (x) x = (x^(1<<(to-1)));
    while (true) {
        dat[at].num++;
        if (x == 0) break;
        int to = bits(x)+1;
        if (x == 0) to = 0;
        if (dat[at].go[to] == MAX-1) {
            dat[at].go[to] = cur++;
        }
        at = dat[at].go[to];
        x = x^(1<<(to-1));
    }
}

int main() {
    setIO("");
    int n; re(n);
    auto high_bit = [&](int x) -> int {
        for (int i = LOG; i >= 0; i--) {
            if ((1<<i)&x) return i;
        }
        return LOG+1;
    };
    vi a(n);
    f0r(i, n) re(a[i]);
    f0r(i, n) ins(a[i]);
    function<int(int)> dfs = [&](int src) -> int {
        int ret = 0;
        vector<int> pre(LOG+2);
        vector<int> suf(LOG+2);
        for (int i = LOG+1; i >= 0; i--) {
            if (i == LOG+1) suf[i] = min(1, dat[dat[src].go[i]].num);
            else suf[i] = suf[i+1] + min(1, dat[dat[src].go[i]].num);
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (i == 0) pre[i] = min(1, dat[dat[src].go[i]].num);
            else pre[i] = max(pre[i-1], min(1, dat[dat[src].go[i]].num));
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (dat[src].go[i] == MAX-1) continue;
            int bef = (i ? pre[i-1] : 0);
            int aft = (i == LOG+1 ? 0 : suf[i+1]);
            int res = bef + dfs(dat[src].go[i]) + aft;
            ckmax(ret, res);
        }
        int val = min(2, dat[src].num);
        ckmax(ret, val);
        return ret;
    };
    int ans = dfs(0);
    ps(n-ans);
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<db, db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int) (x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define resz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define f1r(i, a, b) for(int i = (a); i < (b); ++i)
#define f0r(i, a) f1r(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto& a : x)

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }

constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1, T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T, SZ>& a);
    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class T, class... Ts> void re(T& t, Ts&... ts) {
        re(t); re(ts...); }
    template<class T> void re(complex<T>& x) { T a, b; re(a, b); x = cd(a, b); }
    template<class T1, class T2> void re(pair<T1, T2>& p) { re(p.f, p.s); }
    template<class T> void re(vector<T>& a) { F0R(i, sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T, SZ>& a) { F0R(i, SZ) re(a[i]); }
}

using namespace input;

namespace output {
    void pr(int x) { cout << x; }
    void pr(long x) { cout << x; }
    void pr(ll x) { cout << x; }
    void pr(unsigned x) { cout << x; }
    void pr(unsigned long x) { cout << x; }
    void pr(unsigned long long x) { cout << x; }
    void pr(float x) { cout << x; }
    void pr(double x) { cout << x; }
    void pr(ld x) { cout << x; }
    void pr(char x) { cout << x; }
    void pr(const char* x) { cout << x; }
    void pr(const string& x) { cout << x; }
    void pr(bool x) { pr(x ? "true" : "false"); }
    template<class T> void pr(const complex<T>& x) { cout << x; }
    template<class T1, class T2> void pr(const pair<T1, T2>& x);
    template<class T> void pr(const T& x);
    template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
        pr(t); pr(ts...); }
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{", x.f, ", ", x.s, "}"); }
    template<class T> void pr(const T& x) {
        pr("{"); // const iterator needed for vector<bool>
        bool fst = 1; for (const auto& a: x) pr(!fst ? ", " : "", a), fst = 0;
        pr("}"); }
    void ps() { pr("\n"); } // print w/ spaces
    template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); }
    void pc() { pr("]\n"); } // debug w/ commas
    template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(), "r", stdin); }
    void setOut(string s) { freopen(s.c_str(), "w", stdout); }
    void setIO(string s = "") {
        cin.sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); }
    }
}

using namespace io;

const int MOD = 1e9 + 7; // 998244353;
const ld PI = acos((ld) -1);

typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator << (ostream& os, const mi& a) { return os << a.val; }
    friend void pr(const mi& a) { pr(a.val); }
    friend void re(mi& a) { ll x; re(x); a = mi(x); }
    friend bool operator == (const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator != (const mi& a, const mi& b) { return !(a == b); }
    friend bool operator < (const mi& a, const mi& b) { return a.val < b.val; }
    friend bool operator > (const mi& a, const mi& b) { return a.val > b.val; }
    friend bool operator <= (const mi& a, const mi& b) { return a.val <= b.val; }
    friend bool operator >= (const mi& a, const mi& b) { return a.val >= b.val; }
    mi operator - () const { return mi(-val); }
    mi& operator += (const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator -= (const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator *= (const mi& m) { val = (ll) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator /= (const mi& m) { return (*this) *= inv(m); }
    friend mi operator + (mi a, const mi& b) { return a += b; }
    friend mi operator - (mi a, const mi& b) { return a -= b; }
    friend mi operator * (mi a, const mi& b) { return a *= b; }
    friend mi operator / (mi a, const mi& b) { return a /= b; }
};

typedef pair<mi, mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;
const int LOG = 30;
const int MAX = 3e6;
struct node {
    map<int, int> go;
    int num;
    node() {
        num = 0;
    }
};
node dat[MAX];
int cur = 1;
void ins(int x) {
    int at = 0;
    dat[at].num++;
    int to = bits(x)+1;
    if (x == 0) to = 0;
    if (dat[at].go.find(to) == dat[at].go.end()) {
        assert(cur<MAX-1);
        dat[at].go[to] = cur++;
    }
    at = dat[at].go[to];
    if (x) x = (x^(1<<(to-1)));
    while (true) {
        dat[at].num++;
        if (x == 0) break;
        int to = bits(x)+1;
        if (x == 0) to = 0;
        if (dat[at].go.find(to) == dat[at].go.end()) {
            assert(cur<MAX-1);
            dat[at].go[to] = cur++;
        }
        at = dat[at].go[to];
        x = x^(1<<(to-1));
    }
}

int main() {
    setIO("");
    int n; re(n);
    auto high_bit = [&](int x) -> int {
        for (int i = LOG; i >= 0; i--) {
            if ((1<<i)&x) return i;
        }
        return LOG+1;
    };
    vi a(n);
    f0r(i, n) re(a[i]);
    f0r(i, n) ins(a[i]);
    function<int(int)> dfs = [&](int src) -> int {
        int ret = 0;
        vector<int> pre(LOG+2);
        vector<int> suf(LOG+2);
        for (int i = LOG+1; i >= 0; i--) {
            int val = 0;
            if (dat[src].go.find(i) != dat[src].go.end()) val = dat[dat[src].go[i]].num;
            if (i == LOG+1) suf[i] = min(1, val);
            else suf[i] = suf[i+1] + min(1, val);
        }
        for (int i = 0; i <= LOG+1; i++) {
            int val = 0;
            if (dat[src].go.find(i) != dat[src].go.end()) val = dat[dat[src].go[i]].num;
            if (i == 0) pre[i] = min(1, val);
            else pre[i] = max(pre[i-1], min(1, val));
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (dat[src].go.find(i) == dat[src].go.end()) continue;
            int bef = (i ? pre[i-1] : 0);
            int aft = (i == LOG+1 ? 0 : suf[i+1]);
            int res = bef + dfs(dat[src].go[i]) + aft;
            ckmax(ret, res);
        }
        int val = min(2, dat[src].num);
        ckmax(ret, val);
        return ret;
    };
    int ans = dfs(0);
    ps(n-ans);
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<db, db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int) (x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define resz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define f1r(i, a, b) for(int i = (a); i < (b); ++i)
#define f0r(i, a) f1r(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto& a : x)

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }

constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1, T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T, SZ>& a);
    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class T, class... Ts> void re(T& t, Ts&... ts) {
        re(t); re(ts...); }
    template<class T> void re(complex<T>& x) { T a, b; re(a, b); x = cd(a, b); }
    template<class T1, class T2> void re(pair<T1, T2>& p) { re(p.f, p.s); }
    template<class T> void re(vector<T>& a) { F0R(i, sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T, SZ>& a) { F0R(i, SZ) re(a[i]); }
}

using namespace input;

namespace output {
    void pr(int x) { cout << x; }
    void pr(long x) { cout << x; }
    void pr(ll x) { cout << x; }
    void pr(unsigned x) { cout << x; }
    void pr(unsigned long x) { cout << x; }
    void pr(unsigned long long x) { cout << x; }
    void pr(float x) { cout << x; }
    void pr(double x) { cout << x; }
    void pr(ld x) { cout << x; }
    void pr(char x) { cout << x; }
    void pr(const char* x) { cout << x; }
    void pr(const string& x) { cout << x; }
    void pr(bool x) { pr(x ? "true" : "false"); }
    template<class T> void pr(const complex<T>& x) { cout << x; }
    template<class T1, class T2> void pr(const pair<T1, T2>& x);
    template<class T> void pr(const T& x);
    template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
        pr(t); pr(ts...); }
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{", x.f, ", ", x.s, "}"); }
    template<class T> void pr(const T& x) {
        pr("{"); // const iterator needed for vector<bool>
        bool fst = 1; for (const auto& a: x) pr(!fst ? ", " : "", a), fst = 0;
        pr("}"); }
    void ps() { pr("\n"); } // print w/ spaces
    template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); }
    void pc() { pr("]\n"); } // debug w/ commas
    template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(), "r", stdin); }
    void setOut(string s) { freopen(s.c_str(), "w", stdout); }
    void setIO(string s = "") {
        cin.sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); }
    }
}

using namespace io;

const int MOD = 1e9 + 7; // 998244353;
const ld PI = acos((ld) -1);

typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator << (ostream& os, const mi& a) { return os << a.val; }
    friend void pr(const mi& a) { pr(a.val); }
    friend void re(mi& a) { ll x; re(x); a = mi(x); }
    friend bool operator == (const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator != (const mi& a, const mi& b) { return !(a == b); }
    friend bool operator < (const mi& a, const mi& b) { return a.val < b.val; }
    friend bool operator > (const mi& a, const mi& b) { return a.val > b.val; }
    friend bool operator <= (const mi& a, const mi& b) { return a.val <= b.val; }
    friend bool operator >= (const mi& a, const mi& b) { return a.val >= b.val; }
    mi operator - () const { return mi(-val); }
    mi& operator += (const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator -= (const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator *= (const mi& m) { val = (ll) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator /= (const mi& m) { return (*this) *= inv(m); }
    friend mi operator + (mi a, const mi& b) { return a += b; }
    friend mi operator - (mi a, const mi& b) { return a -= b; }
    friend mi operator * (mi a, const mi& b) { return a *= b; }
    friend mi operator / (mi a, const mi& b) { return a /= b; }
};

typedef pair<mi, mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;
const int LOG = 30;
const int MAX = (2e5+5)*5;
struct node {
    int go[LOG+2];
    int num;
    node() {
        for (int i = 0; i < LOG+2; i++) go[i] = MAX-1;
        num = 0;
    }
};
node dat[MAX];
int cur = 1;
void ins(int x) {
    int at = 0;
    dat[at].num++;
    int to = bits(x)+1;
    if (x == 0) to = 0;
    if (dat[at].go[to] == MAX-1) {
        assert(cur<MAX-1);
        dat[at].go[to] = cur++;
    }
    at = dat[at].go[to];
    if (x) x = (x^(1<<(to-1)));
    while (true) {
        dat[at].num++;
        if (x == 0) break;
        int to = bits(x)+1;
        if (x == 0) to = 0;
        if (dat[at].go[to] == MAX-1) {
            assert(cur<MAX-1);
            dat[at].go[to] = cur++;
        }
        at = dat[at].go[to];
        x = x^(1<<(to-1));
    }
}

int main() {
    setIO("");
    int n; re(n);
    auto high_bit = [&](int x) -> int {
        for (int i = LOG; i >= 0; i--) {
            if ((1<<i)&x) return i;
        }
        return LOG+1;
    };
    vi a(n);
    f0r(i, n) re(a[i]);
    f0r(i, n) ins(a[i]);
    function<int(int)> dfs = [&](int src) -> int {
        int ret = 0;
        vector<int> pre(LOG+2);
        vector<int> suf(LOG+2);
        for (int i = LOG+1; i >= 0; i--) {
            if (i == LOG+1) suf[i] = min(1, dat[dat[src].go[i]].num);
            else suf[i] = suf[i+1] + min(1, dat[dat[src].go[i]].num);
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (i == 0) pre[i] = min(1, dat[dat[src].go[i]].num);
            else pre[i] = max(pre[i-1], min(1, dat[dat[src].go[i]].num));
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (dat[src].go[i] == MAX-1) continue;
            int bef = (i ? pre[i-1] : 0);
            int aft = (i == LOG+1 ? 0 : suf[i+1]);
            int res = bef + dfs(dat[src].go[i]) + aft;
            ckmax(ret, res);
        }
        int val = min(2, dat[src].num);
        ckmax(ret, val);
        return ret;
    };
    int ans = dfs(0);
    ps(n-ans);
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<db, db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int) (x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define resz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define f1r(i, a, b) for(int i = (a); i < (b); ++i)
#define f0r(i, a) f1r(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto& a : x)

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }

constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1, T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T, SZ>& a);
    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class T, class... Ts> void re(T& t, Ts&... ts) {
        re(t); re(ts...); }
    template<class T> void re(complex<T>& x) { T a, b; re(a, b); x = cd(a, b); }
    template<class T1, class T2> void re(pair<T1, T2>& p) { re(p.f, p.s); }
    template<class T> void re(vector<T>& a) { F0R(i, sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T, SZ>& a) { F0R(i, SZ) re(a[i]); }
}

using namespace input;

namespace output {
    void pr(int x) { cout << x; }
    void pr(long x) { cout << x; }
    void pr(ll x) { cout << x; }
    void pr(unsigned x) { cout << x; }
    void pr(unsigned long x) { cout << x; }
    void pr(unsigned long long x) { cout << x; }
    void pr(float x) { cout << x; }
    void pr(double x) { cout << x; }
    void pr(ld x) { cout << x; }
    void pr(char x) { cout << x; }
    void pr(const char* x) { cout << x; }
    void pr(const string& x) { cout << x; }
    void pr(bool x) { pr(x ? "true" : "false"); }
    template<class T> void pr(const complex<T>& x) { cout << x; }
    template<class T1, class T2> void pr(const pair<T1, T2>& x);
    template<class T> void pr(const T& x);
    template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
        pr(t); pr(ts...); }
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{", x.f, ", ", x.s, "}"); }
    template<class T> void pr(const T& x) {
        pr("{"); // const iterator needed for vector<bool>
        bool fst = 1; for (const auto& a: x) pr(!fst ? ", " : "", a), fst = 0;
        pr("}"); }
    void ps() { pr("\n"); } // print w/ spaces
    template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); }
    void pc() { pr("]\n"); } // debug w/ commas
    template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
        pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(), "r", stdin); }
    void setOut(string s) { freopen(s.c_str(), "w", stdout); }
    void setIO(string s = "") {
        cin.sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); }
    }
}

using namespace io;

const int MOD = 1e9 + 7; // 998244353;
const ld PI = acos((ld) -1);

typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator << (ostream& os, const mi& a) { return os << a.val; }
    friend void pr(const mi& a) { pr(a.val); }
    friend void re(mi& a) { ll x; re(x); a = mi(x); }
    friend bool operator == (const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator != (const mi& a, const mi& b) { return !(a == b); }
    friend bool operator < (const mi& a, const mi& b) { return a.val < b.val; }
    friend bool operator > (const mi& a, const mi& b) { return a.val > b.val; }
    friend bool operator <= (const mi& a, const mi& b) { return a.val <= b.val; }
    friend bool operator >= (const mi& a, const mi& b) { return a.val >= b.val; }
    mi operator - () const { return mi(-val); }
    mi& operator += (const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator -= (const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator *= (const mi& m) { val = (ll) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, ll p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator /= (const mi& m) { return (*this) *= inv(m); }
    friend mi operator + (mi a, const mi& b) { return a += b; }
    friend mi operator - (mi a, const mi& b) { return a -= b; }
    friend mi operator * (mi a, const mi& b) { return a *= b; }
    friend mi operator / (mi a, const mi& b) { return a /= b; }
};

typedef pair<mi, mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;
const int LOG = 30;
const int MAX = (2e5+5)*5;
struct node {
    int go[LOG+2];
    int num;
    node() {
        for (int i = 0; i < LOG+2; i++) go[i] = MAX-1;
        num = 0;
    }
};
node dat[MAX];
int cur = 1;
void ins(int x) {
    int at = 0;
    dat[at].num++;
    int to = bits(x)+1;
    if (x == 0) to = 0;
    if (dat[at].go[to] == MAX-1) {
        assert(cur<MAX-1);
        dat[at].go[to] = cur++;
    }
    at = dat[at].go[to];
    if (x) x = (x^(1<<(to-1)));
    while (true) {
        dat[at].num++;
        if (x == 0) break;
        int to = bits(x)+1;
        if (x == 0) to = 0;
        if (dat[at].go[to] == MAX-1) {
            dat[at].go[to] = cur++;
        }
        at = dat[at].go[to];
        x = x^(1<<(to-1));
    }
}

int main() {
    setIO("");
    int n; re(n);
    auto high_bit = [&](int x) -> int {
        for (int i = LOG; i >= 0; i--) {
            if ((1<<i)&x) return i;
        }
        return LOG+1;
    };
    vi a(n);
    f0r(i, n) re(a[i]);
    f0r(i, n) ins(a[i]);
    function<int(int)> dfs = [&](int src) -> int {
        int ret = 0;
        vector<int> pre(LOG+2);
        vector<int> suf(LOG+2);
        for (int i = LOG+1; i >= 0; i--) {
            if (i == LOG+1) suf[i] = min(1, dat[dat[src].go[i]].num);
            else suf[i] = suf[i+1] + min(1, dat[dat[src].go[i]].num);
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (i == 0) pre[i] = min(1, dat[dat[src].go[i]].num);
            else pre[i] = max(pre[i-1], min(1, dat[dat[src].go[i]].num));
        }
        for (int i = 0; i <= LOG+1; i++) {
            if (dat[src].go[i] == MAX-1) continue;
            int bef = (i ? pre[i-1] : 0);
            int aft = (i == LOG+1 ? 0 : suf[i+1]);
            int res = bef + dfs(dat[src].go[i]) + aft;
            ckmax(ret, res);
        }
        int val = min(2, dat[src].num);
        ckmax(ret, val);
        return ret;
    };
    int ans = dfs(0);
    ps(n-ans);
    return 0;
}


//template start//
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forl(i, n) for(long long i=0;i<n;++i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pi>
#define vpl vector<pl>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define all(x) x.begin(),x.end()
typedef long double ld;
typedef double dd;
typedef long long ll;
const int MOD = 998244353; // = (119<<23)+1
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
//intitialization->ordered_set<int>  s;.....can do all set functions.......s.order_of_key(2)(// the number of elements in the set s strictly less than 2)
//use this ->   using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//*s.find_by_order(0)(print the 0-th smallest number in s(0-based)).....
template<typename T>
void printvector(vector<T>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i]<<' ';
    }
    cout<<"\n";
}
template<typename T>
void printarray(T a[])
{
    for(int i=0;i<a.size();i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void printpairs(vector<pair<int,int>>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i].F<<','<<v[i].S<<'|';
    }
    cout<<endl;
}

void print2d(vector<vector<int>>&v){
    for(int i=0;i<v.size();i++){
        printvector(v[i]);
    }
}
//exponent in log(m) time
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
//nCr with modulo
ll R=MOD;
// modinv((x-1)!)=modinv(x)*x
ll modInverse(ll n) {
    return exp(n, R-2,R);
}
ll ncr(ll n, ll r)
{
    if (r==0) return 1;
        vector<ll>fac(n+1,1);
        for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%R;
        return ((fac[n]*modInverse(fac[r]) % R)*modInverse(fac[n-r])%R)%R;
}
//prime factorization can be done in log(n) after a precomputaion of O(nlog(log(n)))
//(In sieve storing the smallest prime factor of each number upto n)
//sieve for spf
void sieve(int n,vi&spf)
{
    for(int i=0;i<n;i++) spf[i]=i;
    for(int i=2;i<n;i++)
    {
        if(spf[i]==i)
        {
            for(ll j=((ll)i)*((ll)i);j<n;j+=i)
            {
                if(spf[j]==j) spf[j]=i;
            }
        }
    }
}
//prime factorization in root(n)//
void factorize(long long n,vpi&v)
{
    int count = 0;
    while (!(n % 2)) {
        n >>= 1;
        count++;
    }

    if (count)
        v.push_back(make_pair(2,count));

    for (long long i = 3; i <= sqrt(n); i += 2) {
        count = 0;
        while (n % i == 0) {
            count++;
            n = n / i;
        }
        if (count)
            v.push_back(make_pair(i,count));
    }

    if (n > 2)
        v.push_back(make_pair(n,1));
}
//2d grids
int mv_x[]={0,0,1,-1};
int mv_y[]={1,-1,0,0};
//
#define TT int T;cin>>T;for(int tt=1;tt<=T;tt++)
//template ends//
//ImpPoints
//1) string insert function is way faster than loop insertion
//2)Use binary exp instead of log,pow(they work well with doubles)
//3)if accesing any index then keep check that the index exists
//4) use(int) with v.size() calculations always.
vi x;
int ans=0;
void solve(int bit)
{
    vi on,off;
    if(bit==-1) return;
    for(auto val:x)
    {
        if(((1<<bit)&val)==1)
        {
            on.pb(val);
        }
        else
        {
            off.pb(val);
        }
    }
    //cout<<bit<<" "<<on.size()<<" "<<off.size()<<endl;
    if(on.size()>=2&&off.size()>=2)
    {
        ans+=min(on.size(),off.size())-1;
    }
    if(on.size()<=1&&off.size()<=1)
    {
        return;
    }
    if(on.size()>off.size())
    {
        x.clear();
        x=on;
        solve(bit-1);
    }
    else
    {
        x.clear();
        x=off;
        solve(bit-1);
    }
    return;
}
int main()
{
    fast;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int xx;
        cin>>xx;
        x.pb(xx);
    }
    solve(31);
    cout<<ans<<endl;
}


//template start//
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forl(i, n) for(long long i=0;i<n;++i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pi>
#define vpl vector<pl>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define all(x) x.begin(),x.end()
typedef long double ld;
typedef double dd;
typedef long long ll;
const int MOD = 998244353; // = (119<<23)+1
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
//intitialization->ordered_set<int>  s;.....can do all set functions.......s.order_of_key(2)(// the number of elements in the set s strictly less than 2)
//use this ->   using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//*s.find_by_order(0)(print the 0-th smallest number in s(0-based)).....
template<typename T>
void printvector(vector<T>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i]<<' ';
    }
    cout<<"\n";
}
template<typename T>
void printarray(T a[])
{
    for(int i=0;i<a.size();i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void printpairs(vector<pair<int,int>>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i].F<<','<<v[i].S<<'|';
    }
    cout<<endl;
}

void print2d(vector<vector<int>>&v){
    for(int i=0;i<v.size();i++){
        printvector(v[i]);
    }
}
//exponent in log(m) time
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
//nCr with modulo
ll R=MOD;
// modinv((x-1)!)=modinv(x)*x
ll modInverse(ll n) {
    return exp(n, R-2,R);
}
ll ncr(ll n, ll r)
{
    if (r==0) return 1;
        vector<ll>fac(n+1,1);
        for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%R;
        return ((fac[n]*modInverse(fac[r]) % R)*modInverse(fac[n-r])%R)%R;
}
//prime factorization can be done in log(n) after a precomputaion of O(nlog(log(n)))
//(In sieve storing the smallest prime factor of each number upto n)
//sieve for spf
void sieve(int n,vi&spf)
{
    for(int i=0;i<n;i++) spf[i]=i;
    for(int i=2;i<n;i++)
    {
        if(spf[i]==i)
        {
            for(ll j=((ll)i)*((ll)i);j<n;j+=i)
            {
                if(spf[j]==j) spf[j]=i;
            }
        }
    }
}
//prime factorization in root(n)//
void factorize(long long n,vpi&v)
{
    int count = 0;
    while (!(n % 2)) {
        n >>= 1;
        count++;
    }

    if (count)
        v.push_back(make_pair(2,count));

    for (long long i = 3; i <= sqrt(n); i += 2) {
        count = 0;
        while (n % i == 0) {
            count++;
            n = n / i;
        }
        if (count)
            v.push_back(make_pair(i,count));
    }

    if (n > 2)
        v.push_back(make_pair(n,1));
}
//2d grids
int mv_x[]={0,0,1,-1};
int mv_y[]={1,-1,0,0};
//
#define TT int T;cin>>T;for(int tt=1;tt<=T;tt++)
//template ends//
//ImpPoints
//1) string insert function is way faster than loop insertion
//2)Use binary exp instead of log,pow(they work well with doubles)
//3)if accesing any index then keep check that the index exists
//4) use(int) with v.size() calculations always.
int ans=0;
int solve(vi x,int bit)
{
    vi on,off;
    int temp=0;
    if(bit==-1) return 0;
    for(auto val:x)
    {
        if(((1<<bit)&val))
        {
            on.pb(val);
        }
        else
        {
            off.pb(val);
        }
    }
    //cout<<bit<<" "<<on.size()<<" "<<off.size()<<endl;
    if(on.size()>=2&&off.size()>=2)
    {
        temp+=min(on.size()-1+solve(off,bit-1),off.size()-1+solve(on,bit-1));
    }
    if(on.size()<=1&&off.size()<=1)
    {
        return 0;
    }
    if(on.size()>1)
    {
        temp+=solve(on,bit-1);
    }
    else
    {
        temp+=solve(off,bit-1);
    }
    return temp;
}
int main()
{
    fast;
    int n;
    cin>>n;
    vi v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    int ans=solve(v,31);
    cout<<ans<<endl;
}


//template start//
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forl(i, n) for(long long i=0;i<n;++i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pi>
#define vpl vector<pl>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define all(x) x.begin(),x.end()
typedef long double ld;
typedef double dd;
typedef long long ll;
const int MOD = 998244353; // = (119<<23)+1
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
//intitialization->ordered_set<int>  s;.....can do all set functions.......s.order_of_key(2)(// the number of elements in the set s strictly less than 2)
//use this ->   using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//*s.find_by_order(0)(print the 0-th smallest number in s(0-based)).....
template<typename T>
void printvector(vector<T>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i]<<' ';
    }
    cout<<"\n";
}
template<typename T>
void printarray(T a[])
{
    for(int i=0;i<a.size();i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void printpairs(vector<pair<int,int>>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i].F<<','<<v[i].S<<'|';
    }
    cout<<endl;
}

void print2d(vector<vector<int>>&v){
    for(int i=0;i<v.size();i++){
        printvector(v[i]);
    }
}
//exponent in log(m) time
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
//nCr with modulo
ll R=MOD;
// modinv((x-1)!)=modinv(x)*x
ll modInverse(ll n) {
    return exp(n, R-2,R);
}
ll ncr(ll n, ll r)
{
    if (r==0) return 1;
        vector<ll>fac(n+1,1);
        for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%R;
        return ((fac[n]*modInverse(fac[r]) % R)*modInverse(fac[n-r])%R)%R;
}
//prime factorization can be done in log(n) after a precomputaion of O(nlog(log(n)))
//(In sieve storing the smallest prime factor of each number upto n)
//sieve for spf
void sieve(int n,vi&spf)
{
    for(int i=0;i<n;i++) spf[i]=i;
    for(int i=2;i<n;i++)
    {
        if(spf[i]==i)
        {
            for(ll j=((ll)i)*((ll)i);j<n;j+=i)
            {
                if(spf[j]==j) spf[j]=i;
            }
        }
    }
}
//prime factorization in root(n)//
void factorize(long long n,vpi&v)
{
    int count = 0;
    while (!(n % 2)) {
        n >>= 1;
        count++;
    }

    if (count)
        v.push_back(make_pair(2,count));

    for (long long i = 3; i <= sqrt(n); i += 2) {
        count = 0;
        while (n % i == 0) {
            count++;
            n = n / i;
        }
        if (count)
            v.push_back(make_pair(i,count));
    }

    if (n > 2)
        v.push_back(make_pair(n,1));
}
//2d grids
int mv_x[]={0,0,1,-1};
int mv_y[]={1,-1,0,0};
//
#define TT int T;cin>>T;for(int tt=1;tt<=T;tt++)
//template ends//
//ImpPoints
//1) string insert function is way faster than loop insertion
//2)Use binary exp instead of log,pow(they work well with doubles)
//3)if accesing any index then keep check that the index exists
//4) use(int) with v.size() calculations always.
vi x;
int ans=0;
void solve(int bit)
{
    vi on,off;
    if(bit==-1) return;
    for(auto val:x)
    {
        if(((1<<bit)&val))
        {
            on.pb(val);
        }
        else
        {
            off.pb(val);
        }
    }
    //cout<<bit<<" "<<on.size()<<" "<<off.size()<<endl;
    if(on.size()>=2&&off.size()>=2)
    {
        ans+=min(on.size(),off.size())-1;
    }
    if(on.size()<=1&&off.size()<=1)
    {
        return;
    }
    if(on.size()>off.size())
    {
        x.clear();
        x=on;
        solve(bit-1);
    }
    else
    {
        x.clear();
        x=off;
        solve(bit-1);
    }
    return;
}
int main()
{
    fast;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int xx;
        cin>>xx;
        x.pb(xx);
    }
    solve(31);
    cout<<ans<<endl;
}


//template start//
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forl(i, n) for(long long i=0;i<n;++i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pi>
#define vpl vector<pl>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define all(x) x.begin(),x.end()
typedef long double ld;
typedef double dd;
typedef long long ll;
const int MOD = 998244353; // = (119<<23)+1
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
//intitialization->ordered_set<int>  s;.....can do all set functions.......s.order_of_key(2)(// the number of elements in the set s strictly less than 2)
//use this ->   using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//*s.find_by_order(0)(print the 0-th smallest number in s(0-based)).....
template<typename T>
void printvector(vector<T>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i]<<' ';
    }
    cout<<"\n";
}
template<typename T>
void printarray(T a[])
{
    for(int i=0;i<a.size();i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void printpairs(vector<pair<int,int>>& v){
    for(int i=0;i<v.size();i++){
        cout<<v[i].F<<','<<v[i].S<<'|';
    }
    cout<<endl;
}

void print2d(vector<vector<int>>&v){
    for(int i=0;i<v.size();i++){
        printvector(v[i]);
    }
}
//exponent in log(m) time
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
//nCr with modulo
ll R=MOD;
// modinv((x-1)!)=modinv(x)*x
ll modInverse(ll n) {
    return exp(n, R-2,R);
}
ll ncr(ll n, ll r)
{
    if (r==0) return 1;
        vector<ll>fac(n+1,1);
        for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%R;
        return ((fac[n]*modInverse(fac[r]) % R)*modInverse(fac[n-r])%R)%R;
}
//prime factorization can be done in log(n) after a precomputaion of O(nlog(log(n)))
//(In sieve storing the smallest prime factor of each number upto n)
//sieve for spf
void sieve(int n,vi&spf)
{
    for(int i=0;i<n;i++) spf[i]=i;
    for(int i=2;i<n;i++)
    {
        if(spf[i]==i)
        {
            for(ll j=((ll)i)*((ll)i);j<n;j+=i)
            {
                if(spf[j]==j) spf[j]=i;
            }
        }
    }
}
//prime factorization in root(n)//
void factorize(long long n,vpi&v)
{
    int count = 0;
    while (!(n % 2)) {
        n >>= 1;
        count++;
    }

    if (count)
        v.push_back(make_pair(2,count));

    for (long long i = 3; i <= sqrt(n); i += 2) {
        count = 0;
        while (n % i == 0) {
            count++;
            n = n / i;
        }
        if (count)
            v.push_back(make_pair(i,count));
    }

    if (n > 2)
        v.push_back(make_pair(n,1));
}
//2d grids
int mv_x[]={0,0,1,-1};
int mv_y[]={1,-1,0,0};
//
#define TT int T;cin>>T;for(int tt=1;tt<=T;tt++)
//template ends//
//ImpPoints
//1) string insert function is way faster than loop insertion
//2)Use binary exp instead of log,pow(they work well with doubles)
//3)if accesing any index then keep check that the index exists
//4) use(int) with v.size() calculations always.
int ans=0;
int solve(vi x,int bit)
{
    vi on,off;
    int temp=0;
    if(bit==-1) return 0;
    for(auto val:x)
    {
        if(((1<<bit)&val))
        {
            on.pb(val);
        }
        else
        {
            off.pb(val);
        }
    }
    //cout<<bit<<" "<<on.size()<<" "<<off.size()<<endl;
    if(on.size()>=2&&off.size()>=2)
    {
        temp+=min(on.size()-1+solve(off,bit-1),off.size()-1+solve(on,bit-1));
    }
    else if(on.size()<=1&&off.size()<=1)
    {
        return 0;
    }
    else if(on.size()>1)
    {
        temp+=solve(on,bit-1);
    }
    else
    {
        temp+=solve(off,bit-1);
    }
    return temp;
}
int main()
{
    fast;
    int n;
    cin>>n;
    vi v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    int ans=solve(v,31);
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define int int64_t
#define vi vector<int>
#define ii pair<int,int>
#define vb vector<bool>
#define vvi vector<vi>
#define vvb vector<vb>
#define vii vector<ii>
#define vvii vector<vii>
#define x first
#define y second
#define pb push_back
#define loop(i,s,e) for(int i=s;i<e;i++)
#define loopr(i,s,e) for(int i=e-1;i>=s;i--)
#define chkmax(a,b) a = max(a,b)
#define chkmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
using namespace std;
const int INF = 4e18;

const int LOG = 32;

int32_t main(){
    ios_base::sync_with_stdio(false);
    int n; cin>>n;
    vi cnt(LOG);
    loop(i,0,n){
        int32_t x; cin>>x;
        cnt[31-__builtin_clz(x)]++;
    }
    int ans = 0;
    loop(i,0,LOG){
        chkmax(ans, cnt[i]-1);
    }
    loop(i,0,LOG) ans+=(cnt[i]!=0);
    cout<<n-ans<<endl;
    return 0;
}
/*
color a
cls
g++ c.cpp -o a & a
5
0 1 5 2 6

*/


#include <bits/stdc++.h>
#define int int64_t
#define vi vector<int>
#define ii pair<int,int>
#define vb vector<bool>
#define vvi vector<vi>
#define vvb vector<vb>
#define vii vector<ii>
#define vvii vector<vii>
#define x first
#define y second
#define pb push_back
#define loop(i,s,e) for(int i=s;i<e;i++)
#define loopr(i,s,e) for(int i=e-1;i>=s;i--)
#define chkmax(a,b) a = max(a,b)
#define chkmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
using namespace std;
const int INF = 4e18;

const int LOG = 32;

int32_t main(){
    ios_base::sync_with_stdio(false);
    int n; cin>>n;
    vi cnt(LOG);
    loop(i,0,n){
        int x; cin>>x;
        int j = 0;
        while(x>1) x/=2, j++;
        cnt[j]++;
    }
    int ans = -1;
    loop(i,0,LOG){
        chkmax(ans, cnt[i]-1);
    }
    loop(i,0,LOG) ans+=(cnt[i]!=0);
    cout<<n-ans<<endl;
    return 0;
}
/*
color a
cls
g++ c.cpp -o a & a
5
0 1 5 2 6

*/


#include <bits/stdc++.h>
#define int int64_t
#define vi vector<int>
#define ii pair<int,int>
#define vb vector<bool>
#define vvi vector<vi>
#define vvb vector<vb>
#define vii vector<ii>
#define vvii vector<vii>
#define x first
#define y second
#define pb push_back
#define loop(i,s,e) for(int i=s;i<e;i++)
#define loopr(i,s,e) for(int i=e-1;i>=s;i--)
#define chkmax(a,b) a = max(a,b)
#define chkmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
using namespace std;
const int INF = 4e18;

const int LOG = 32;

int32_t main(){
    ios_base::sync_with_stdio(false);
    int n; cin>>n;
    vi cnt(LOG);
    loop(i,0,n){
        int x; cin>>x;
        int j = 0;
        while(x) x/=2, j++;
        cnt[j]++;
    }
    vi suf(LOG+1);
    loopr(i,0,LOG) suf[i] = suf[i+1] + (cnt[i]!=0);
    int ans = 0, c = 0;
    loop(i,0,LOG){
        if (!cnt[i]) continue;
        chkmax(ans, cnt[i] + suf[i+1] + (c!=0));
        c+=cnt[i];
    }
    cout<<n-ans<<endl;
    return 0;
}
/*
color a
cls
g++ c.cpp -o a & a
5
0 1 5 2 6

*/


#include <bits/stdc++.h>
#define int int64_t
#define vi vector<int>
#define ii pair<int,int>
#define vb vector<bool>
#define vvi vector<vi>
#define vvb vector<vb>
#define vii vector<ii>
#define vvii vector<vii>
#define x first
#define y second
#define pb push_back
#define loop(i,s,e) for(int i=s;i<e;i++)
#define loopr(i,s,e) for(int i=e-1;i>=s;i--)
#define chkmax(a,b) a = max(a,b)
#define chkmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
using namespace std;
const int INF = 4e18;

const int LOG = 34;

int solve(vi &a){
    int n = a.size();
    if (n==0) return 0;
    if (n==1) return 1;
    vvi nums(LOG);
    loop(i,0,n){
        int x = a[i];
        int j = 0;
        while(x) x/=2, j++;
        nums[j].pb(a[i]^(1<<(j-1)));
    }
    vi suf(LOG+1,0);
    loopr(i,0,LOG) suf[i] = suf[i+1] + (nums[i].size()!=0);
    if (suf[1]==0){
        return nums[0].size();
    }
    vi sol(LOG);
    loop(i,0,LOG) sol[i] = solve(nums[i]);
    int ans = 0, c = 0;
    loop(i,0,LOG){
        if (sol[i]==0) continue;
        chkmax(ans, sol[i] + suf[i+1] + (c!=0));
        c=1;
    }
    return ans;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    int n; cin>>n;
    vi a(n);
    loop(i,0,n){
        cin>>a[i];
    }
    cout<<n-solve(a)<<endl;
    return 0;
}
/*
color a
cls
g++ c.cpp -o a & a
4
4 5 6 7

5
0 1 5 2 6

*/


#include <bits/stdc++.h>
#define int int64_t
#define vi vector<int>
#define ii pair<int,int>
#define vb vector<bool>
#define vvi vector<vi>
#define vvb vector<vb>
#define vii vector<ii>
#define vvii vector<vii>
#define x first
#define y second
#define pb push_back
#define loop(i,s,e) for(int i=s;i<e;i++)
#define loopr(i,s,e) for(int i=e-1;i>=s;i--)
#define chkmax(a,b) a = max(a,b)
#define chkmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
using namespace std;
const int INF = 4e18;

const int LOG = 32;

int32_t main(){
    ios_base::sync_with_stdio(false);
    int n; cin>>n;
    vi cnt(LOG);
    loop(i,0,n){
        int x; cin>>x;
        int j = 0;
        while(x>1) x/=2, j++;
        cnt[j]++;
    }
    int ans = -1;
    loop(i,0,LOG){
        chkmax(ans, cnt[i]-1);
    }
    loop(i,0,LOG) ans+=(cnt[i]!=0);
    cout<<ans<<endl;
    cout<<n-ans<<endl;
    return 0;
}
/*
color a
cls
g++ c.cpp -o a & a
5
0 1 5 2 6

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef long double ld;
typedef vector<int> vt;
typedef vector<vt> vtt;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
#define pb push_back
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 33;
int bit[MAX],wh[MAX];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		int r;
		scanf("%d",&r);
		int wh = -1;
		for(int e=0;e<30;e++) if(r&(1<<e)) wh = e;
		bit[wh+1]++;
	}
	for(int e=0;e<=30;e++){
		if(bit[e]==1){
			int wh = -1;
			for(int p=e-1;p>=0;p--){
				if(bit[p]){
					wh = p;
					break;
				}
			}
			if(wh!=-1) {
				bit[e] = 0;
				bit[wh]++;
			}
		}
	}
	vector<int> v;
	for(int e=0;e<=30;e++) if(bit[e]) v.push_back(bit[e]);
	sort(all(v));
	int ans = 0;
	for(int e=0;e<sz(v)-1;e++) ans += v[e] - 1;
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef long double ld;
typedef vector<int> vt;
typedef vector<vt> vtt;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
#define pb push_back
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 33;
int bit[MAX],lv[MAX],arr[202020];
vector<int> tmp,v;
void dfs(int x){
	if(sz(tmp)==0) return;
	else if(sz(tmp)==2){
		v.push_back(2);
		return;
	}
	else if(sz(tmp)==1){
		v.push_back(1);
		return;
	}
	vector<int> f1,f2;
	for(int e=0;e<sz(tmp);e++){
		if(tmp[e]&(1<<x)) f2.push_back(tmp[e]);
		else f1.push_back(tmp[e]);
	}
	tmp = f1;
	dfs(x-1);
	tmp = f2;
	dfs(x-1);
}
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++) scanf("%d",&arr[e]);
	for(int e=0;e<n;e++) tmp.push_back(arr[e]);
	dfs(30);
	int ans = 1e9;
	for(int e=0;e<sz(v);e++){
		int f1 = 0,f2 = 0;
		for(int p=0;p<e;p++) f1 += v[p];
		for(int p=e+1;p<sz(v);p++) f2 += (v[p]-1);
		int tot = f2;
		if(f1) tot += (f1-1);
		ans = min(ans,tot);
	}
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef long double ld;
typedef vector<int> vt;
typedef vector<vt> vtt;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
#define pb push_back
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 33;
int bit[MAX],lv[MAX],arr[202020];
vector<int> tmp;
pi dfs(int x){
	if(sz(tmp)==0) return mk(0,0);
	else if(sz(tmp)==2){
		return mk(2,0);
	}
	else if(sz(tmp)==1){
		return mk(1,0);
	}
	vector<int> f1,f2;
	for(int e=0;e<sz(tmp);e++){
		if(tmp[e]&(1<<x)) f2.push_back(tmp[e]);
		else f1.push_back(tmp[e]);
	}
	tmp = f1;
	pi s1 = dfs(x-1);
	tmp = f2;
	pi s2 = dfs(x-1);
	if(s1.x==0) return s2;
	if(s2.x==0) return s1;
	int x1 = max(s1.x,s2.x)+1;
	int x2 = s1.y + s2.y + min(s1.x,s2.x) - 1;
	return mk(x1,x2);
}
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++) scanf("%d",&arr[e]);
	for(int e=0;e<n;e++) tmp.push_back(arr[e]);
	printf("%d\n",dfs(30).y);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef long double ld;
typedef vector<int> vt;
typedef vector<vt> vtt;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
#define pb push_back
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 33;
int bit[MAX],lv[MAX];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		int r;
		scanf("%d",&r);
		int wh = -1;
		for(int p=0;p<30;p++) if(r&(1<<p)) wh = p;
		bit[wh+1]++;
	}
	vector<int> v;
	for(int e=0;e<=30;e++) if(bit[e]) v.push_back(bit[e]);
	int ans = 1e9;
	for(int e=0;e<sz(v);e++){
		if(v[e]==1) continue;
		int f1 = 0,f2 = 0;
		for(int p=0;p<e;p++) f1 += v[p];
		for(int p=e+1;p<sz(v);p++) f2 += (v[p]-1);
		int tot = f2;
		if(f1) tot += (f1-1);
		ans = min(ans,tot);
	}
	if(ans==1e9) ans = 0;
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef long double ld;
typedef vector<int> vt;
typedef vector<vt> vtt;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
#define pb push_back
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 33;
int bit[MAX],wh[MAX];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		int r;
		scanf("%d",&r);
		int wh = -1;
		for(int e=0;e<30;e++) if(r&(1<<e)) wh = e;
		bit[wh+1]++;
	}
	for(int e=0;e<=30;e++){
		if(bit[e]==1){
			int wh = -1;
			for(int p=e-1;p>=0;p--){
				if(bit[p]){
					wh = p;
					break;
				}
			}
			if(wh!=-1) {
				bit[e] = 0;
				bit[wh]++;
			}
		}
	}
	for(int e=0;e<=30;e++){
		if(bit[e]==1){
			int wh = -1;
			for(int p=e+1;p<=30;p++){
				if(bit[p]){
					wh = p;
					break;
				}
			}
			if(wh!=-1){
				 bit[e] = 0;
				 bit[wh]++;
			}
		}
	}
	vector<int> v;
	for(int e=0;e<=30;e++) if(bit[e]) v.push_back(bit[e]);
	sort(all(v));
	int ans = 0;
	for(int e=0;e<sz(v)-1;e++) ans += v[e] - 1;
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef long double ld;
typedef vector<int> vt;
typedef vector<vt> vtt;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
#define pb push_back
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 33;
int bit[MAX],lv[MAX];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		int r;
		scanf("%d",&r);
		int wh = -1;
		for(int p=0;p<30;p++) if(r&(1<<p)) wh = p;
		bit[wh+1]++;
	}
	vector<int> v;
	for(int e=0;e<=30;e++) if(bit[e]) v.push_back(bit[e]);
	int ans = 1e9;
	for(int e=0;e<sz(v);e++){
		int f1 = 0,f2 = 0;
		for(int p=0;p<e;p++) f1 += v[p];
		for(int p=e+1;p<sz(v);p++){
			if(v[p]!=1) f2 += (v[p]-1);
		}
		int tot = f2;
		if(f1) tot += (f1-1);
		ans = min(ans,tot);
	}
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef long double ld;
typedef vector<int> vt;
typedef vector<vt> vtt;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
#define pb push_back
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 33;
int bit[MAX],lv[MAX];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		int r;
		scanf("%d",&r);
		int wh = -1;
		for(int e=0;e<30;e++) if(r&(1<<e)) wh = e;
		bit[wh+1]++;
		lv[wh+1] = r;
	}
	for(int e=0;e<=30;e++){
		if(bit[e]==1){
			int wh = -1;
			bool suc = false;
			for(int p=e-1;p>=0;p--){
				if(lv[e]&(1<<p)){
					if(bit[p]){
						bit[p]++;
						bit[e] = 0;
						suc = true;
						break;
					}
				}else{
					if(bit[p]) wh = p;
				}
			}
			if(!suc){
				if(wh!=-1){
					bit[wh]++;
					bit[e] = 0;
				}else{
					for(int p=e+1;p<=30;p++){
						if(bit[p]){
							bit[p]++;
							bit[e] = 0;
							break;
						}
					}
				}
			}
		}
	}
	vector<int> v;
	for(int e=0;e<=30;e++) if(bit[e]) v.push_back(bit[e]);
	int ans = 1e9;
	for(int e=0;e<sz(v);e++){
		int f1 = 0,f2 = 0;
		for(int p=0;p<e;p++) f1 += v[p];
		for(int p=e+1;p<sz(v);p++) f2 += v[p];
		int tot = (f2-(sz(v)-e-1));
		if(f1) tot += (f1-1);
		ans = min(ans,tot);
	}
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef long double ld;
typedef vector<int> vt;
typedef vector<vt> vtt;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
#define pb push_back
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 33;
int bit[MAX],lv[MAX];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		int r;
		scanf("%d",&r);
		int wh = -1;
		for(int p=0;p<30;p++) if(r&(1<<p)) wh = p;
		bit[wh+1]++;
		lv[wh+1] = r;
	}
	for(int e=0;e<=30;e++){
		if(bit[e]==1){
			int wh = -1;
			bool suc = false;
			for(int p=e-1;p>=1;p--){
				if(lv[e]&(1<<(p-1))){
					if(bit[p]){
						bit[p]++;
						bit[e] = 0;
						suc = true;
						break;
					}
				}else{
					if(bit[p]) wh = p;
				}
			}
			if(!suc){
				if(wh!=-1){
					bit[wh]++;
					bit[e] = 0;
				}else{
					for(int p=e+1;p<=30;p++){
						if(bit[p]){
							bit[p]++;
							bit[e] = 0;
							break;
						}
					}
				}
			}
		}
	}
	vector<int> v;
	for(int e=0;e<=30;e++) if(bit[e]) v.push_back(bit[e]);
	int ans = 1e9;
	for(int e=0;e<sz(v);e++){
		int f1 = 0,f2 = 0;
		for(int p=0;p<e;p++) f1 += v[p];
		for(int p=e+1;p<sz(v);p++) f2 += v[p];
		int tot = (f2-(sz(v)-e-1));
		if(f1) tot += (f1-1);
		ans = min(ans,tot);
	}
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef long double ld;
typedef vector<int> vt;
typedef vector<vt> vtt;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
#define pb push_back
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 33;
int bit[MAX];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		int r;
		scanf("%d",&r);
		int wh = -1;
		for(int e=0;e<30;e++) if(r&(1<<e)) wh = e;
		bit[wh+1]++;
	}
	for(int e=0;e<=30;e++){
		if(bit[e]==1){
			int wh = -1;
			for(int p=e-1;p>=0;p--){
				if(bit[p]){
					wh = p;
					break;
				}
			}
			if(wh!=-1) {
				bit[e] = 0;
				bit[wh]++;
			}else{
				for(int p=e+1;p<=30;p++){
					if(bit[p]){
						wh = p;
						break;
					}
				}
				bit[e] = 0;
				bit[wh]++;
			}
		}
	}
	vector<int> v;
	for(int e=0;e<=30;e++) if(bit[e]) v.push_back(bit[e]);
	int ans = 1e9;
	for(int e=0;e<sz(v);e++){
		int f1 = 0,f2 = 0;
		for(int p=0;p<e;p++) f1 += v[p];
		for(int p=e+1;p<sz(v);p++) f2 += v[p];
		int tot = (f2-(sz(v)-e-1));
		if(f1) tot += (f1-1);
		ans = min(ans,tot);
	}
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef long double ld;
typedef vector<int> vt;
typedef vector<vt> vtt;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
#define pb push_back
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 33;
int bit[MAX];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		int r;
		scanf("%d",&r);
		int wh = -1;
		for(int e=0;e<30;e++) if(r&(1<<e)) wh = e;
		bit[wh+1]++;
	}
	for(int e=0;e<=30;e++){
		if(bit[e]==1){
			int wh = -1;
			for(int p=e-1;p>=0;p--){
				if(bit[p]){
					wh = p;
					break;
				}
			}
			if(wh!=-1) {
				bit[e] = 0;
				bit[wh]++;
			}else{
				for(int p=e+1;p<=30;p++){
					if(bit[p]){
						wh = p;
						break;
					}
				}
				bit[e] = 0;
				bit[wh]++;
			}
		}
	}
	vector<int> v;
	for(int e=0;e<=30;e++) if(bit[e]) v.push_back(bit[e]);
	int ans = 1e9;
	for(int e=0;e<sz(v);e++){
		int f1 = 0,f2 = 0;
		for(int p=0;p<e;p++) f1 += v[p];
		for(int p=e+1;p<sz(v);p++) f2+= v[p];
		int tot = (f1-e) + (f2-(sz(v)-e-1));
		ans = min(ans,tot);
	}
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef long double ld;
typedef vector<int> vt;
typedef vector<vt> vtt;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
#define pb push_back
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 33;
int bit[MAX],lv[MAX];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		int r;
		scanf("%d",&r);
		int wh = -1;
		for(int p=0;p<30;p++) if(r&(1<<p)) wh = p;
		bit[wh+1]++;
	}
	vector<int> v;
	for(int e=0;e<=30;e++) if(bit[e]) v.push_back(bit[e]);
	int ans = 1e9;
	for(int e=0;e<sz(v);e++){
		int f1 = 0,f2 = 0;
		for(int p=0;p<e;p++) f1 += v[p];
		for(int p=e+1;p<sz(v);p++) f2 += v[p];
		int tot = (f2-(sz(v)-e-1));
		if(f1) tot += (f1-1);
		ans = min(ans,tot);
	}
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef long double ld;
typedef vector<int> vt;
typedef vector<vt> vtt;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
#define pb push_back
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 33;
int bit[MAX],wh[MAX];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		int r;
		scanf("%d",&r);
		int wh = -1;
		for(int e=0;e<30;e++) if(r&(1<<e)) wh = e;
		bit[wh+1]++;
	}
	for(int e=0;e<=30;e++){
		if(bit[e]==1){
			int wh = -1;
			for(int p=e-1;p>=0;p--){
				if(bit[p]){
					wh = p;
					break;
				}
			}
			if(wh!=-1) {
				bit[e] = 0;
				bit[wh]++;
			}else{
				for(int p=e+1;p<=30;p++){
					if(bit[p]){
						wh = p;
						break;
					}
				}
				bit[e] = 0;
				bit[wh]++;
			}
		}
	}
	vector<int> v;
	for(int e=0;e<=30;e++) if(bit[e]) v.push_back(bit[e]);
	int ans = 1e9;
	for(int e=0;e<sz(v);e++){
		int f1 = 0,f2 = 0;
		for(int p=0;p<e;p++) f1 += v[p];
		for(int p=e+1;p<sz(v);p++) f2+= v[p];
		int tot = 0;
		if(f1) tot += (f1-1);
		if(f2) tot += (f2-1);
		ans = min(ans,tot);
	}
	printf("%d",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7;
int num[31];
int sum[31];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        int d=0;
        while(x)
        {
            x/=2;
            d++;
        }
        num[d]++;
    }
    sum[0]=num[0];
    for(int i=1;i<=30;i++)
        sum[i]=sum[i-1]+num[i];
    int ddd=0;
    int ans=0;
    for(int i=30;i>=0;i--)
    {
        int k=num[i]+ddd;
        if(i!=0&&sum[i-1]) k++;
        ans=max(ans,k);
        if(num[i]) ddd++;
    }
    cout<<n-ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
vector<int>num[30];
int dfs(vector<int>v,int x)
{
    if(x==-1) return v.size();
    if(v.size()<=2) return v.size();
    vector<int>v0,v1;
    for(int i=0;i<v.size();i++)
    {
        if(v[i]&(1<<x))
            v1.push_back(v[i]);
        else
           v0.push_back(v[i]);
    }
    if(v0.size()&&v1.size())
    {
        if(max(v1.size(),v0.size())<=2)
            return max(v1.size(),v0.size())+1;
            return max(dfs(v1,x-1)+1,dfs(v0,x-1)+1);
    }
    else
    {
        if(v0.size()==0)
        {
            if(v1.size()<=2)
                return v1.size();
            return dfs(v1,x-1);
        }
        else
        {
            if(v0.size()<=2)
                return v0.size();
            return dfs(v0,x-1);
        }
    }
}
int ddd[30];
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
      int x;
      cin>>x;
      int d=x;
      int cnt=0;
      while(d)
      {
          cnt++;
          d/=2;
      }
      num[cnt].push_back(x);
  }
  ddd[0]=num[0].size();

  for(int i=1;i<=29;i++) ddd[i]=ddd[i-1]+num[i].size();
  int sum=0;
  int ans=0;
  for(int i=29;i>=0;i--)
  {
      int d=dfs(num[i],i);
      d+=sum;
      if(ddd[i-1]) d++;
      ans=max(ans,d);
      if(num[i].size()) sum++;
  }
  cout<<n-ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
vector<int>num[31];
int dfs(vector<int>v,int x)
{
    if(x==-1) return v.size();
    if(v.size()<=2) return v.size();
    vector<int>v0,v1;
    for(int i=0;i<v.size();i++)
    {
        if(v[i]&(1<<x))
            v1.push_back(v[i]);
        else
           v0.push_back(v[i]);
    }
    if(v0.size()&&v1.size())
    {
        if(max(v1.size(),v0.size())<=2)
            return max(v1.size(),v0.size())+1;
            return max(dfs(v1,x-1)+1,dfs(v0,x-1)+1);
    }
    else
    {
        if(v0.size()==0)
        {
            if(v1.size()<=2)
                return v1.size();
            return dfs(v1,x-1);
        }
        else
        {
            if(v0.size()<=2)
                return v0.size();
            return dfs(v0,x-1);
        }
    }
}
int ddd[31];
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
      int x;
      cin>>x;
      int d=x;
      int cnt=0;
      while(d)
      {
          cnt++;
          d/=2;
      }
      num[cnt].push_back(x);
  }
  ddd[0]=num[0].size();

  for(int i=1;i<=30;i++) ddd[i]=ddd[i-1]+num[i].size();
  int sum=0;
  int ans=0;
  for(int i=29;i>=0;i--)
  {
      int d=dfs(num[i],i);
      d+=sum;
      if(i!=0&&ddd[i-1]) d++;
      ans=max(ans,d);
      if(num[i].size()) sum++;
  }
  cout<<n-ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
vector<int>num[30];
int dfs(vector<int>v,int x)
{
    if(x==-1) return v.size();
    if(v.size()<=2) return v.size();
    vector<int>v0,v1;
    for(int i=0;i<v.size();i++)
    {
        if(v[i]&(1<<x))
            v1.push_back(v[i]);
        else
           v0.push_back(v[i]);
    }
    if(v0.size()&&v1.size())
    {
        if(max(v1.size(),v0.size())<=2)
            return max(v1.size(),v0.size())+1;
            return max(dfs(v1,x-1)+1,dfs(v0,x-1)+1);
    }
    else
    {
        if(v0.size()==0)
        {
            if(v1.size()<=2)
                return v1.size();
            return dfs(v1,x-1);
        }
        else
        {
            if(v0.size()<=2)
                return v0.size();
            return dfs(v0,x-1);
        }
    }
}
int ddd[30];
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
      int x;
      cin>>x;
      int d=x;
      int cnt=0;
      while(d)
      {
          cnt++;
          d/=2;
      }
      num[cnt].push_back(x);
  }
  ddd[0]=num[0].size();

  for(int i=1;i<=29;i++) ddd[i]=ddd[i-1]+num[i].size();
  int sum=0;
  int ans=0;
  for(int i=29;i>=0;i--)
  {
      int d=dfs(num[i],i);
      d+=sum;
      if(i!=0&&ddd[i-1]) d++;
      ans=max(ans,d);
      if(num[i].size()) sum++;
  }
  cout<<n-ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
vector<int>num[31];
int dfs(vector<int>v,int x)
{
    if(x==-1) return v.size();
    if(v.size()<=2) return v.size();
    vector<int>v0,v1;
    for(int i=0;i<v.size();i++)
    {
        if(v[i]&(1<<x))
           v1.push_back(v[i]);
        else
           v0.push_back(v[i]);
    }
    if(v0.size()&&v1.size())
    {
            return max(dfs(v1,x-1)+1,dfs(v0,x-1)+1);
    }
    else
    {
        return max(dfs(v1,x-1),dfs(v0,x-1));
    }
}
int ddd[31];
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
      int x;
      cin>>x;
      int d=x;
      int cnt=0;
      while(d)
      {
          cnt++;
          d/=2;
      }
      num[cnt].push_back(x);
  }
  ddd[0]=num[0].size();

  for(int i=1;i<=30;i++) ddd[i]=ddd[i-1]+num[i].size();
  int sum=0;
  int ans=0;
  for(int i=30;i>=0;i--)
  {
      int d=dfs(num[i],i);
      d+=sum;
      if(i!=0&&ddd[i-1]) d++;
      ans=max(ans,d);
      if(num[i].size()) sum++;
  }
  cout<<n-ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;

int Solve(int *a, int *b) {
	if (b - a == 1) return 1;
	int k = 1 << __lg(*a ^ *(b - 1));
	int *c = partition_point(a, b, [&](int x) { return (x & k) == 0; });
	return 1 + max(Solve(a, c), Solve(c, b));
}

int main(){
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; ++i) cin >> a[i];
	sort(a, a + n);
	cout << n - Solve(a, a + n) << '\n';
}


#include <bits/extc++.h>
using namespace std;

const int maxn = 200000;

struct UF {
	int p[maxn];
	void init(int n) {
		fill(p, p + n, -1);
	}
	int get(int s) { return p[s] < 0 ? s : (p[s] = get(p[s])); }
	int sz(int s) { return -p[get(s)]; }
	bool unite(int a, int b) {
		a = get(a); b = get(b);
		if (a != b) {
			if (p[b] < p[a]) swap(a, b);
			p[a] += p[b];
			p[b] = a;
		}
		return a != b;
	}
} uf;

int a[maxn];
int n;

__gnu_pbds::gp_hash_table<int, int> h[30];

void Modify(int x, int y) {
	for (int j = 0; j < 30; ++j) {
		h[j][x] += y;
		x &= ~(1 << j);
	}
}

int Smallest(int i) {
	Modify(a[i], -1);
	int k = 0;
	for (int j = 29; j >= 0; --j) {
		if (h[j][k + (a[i] & (1 << j))]) k += a[i] & (1 << j);
		else k += (~a[i]) & (1 << j);
	}
	int j = lower_bound(a, a + n, k) - a;
	Modify(a[i], 1);
	return j;
}

int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin.exceptions(cin.failbit);

	cin >> n;
	uf.init(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		Modify(a[i], 1);
	}
	sort(a, a + n);
	for (int i = 0; i < n; ++i) {
		int j = Smallest(i);
		uf.unite(i, j);
	}
	int b = 0;
	for (int i = 0; i < n; ++i) {
		if (uf.sz(i) > uf.sz(b)) {
			b = uf.get(i);
		}
	}
	int r = 0;
	for (int i = 0; i < n; ++i) {
		int j = Smallest(i);
		if (uf.get(j) != uf.get(b) && uf.get(i) != uf.get(b)) {
			r++;
			Modify(a[i], -1);
		} else {
			uf.unite(i, j);
			uf.unite(j, b);
		}
	}
	cout << r << '\n';
}


#include <bits/extc++.h>
using namespace std;

const int maxn = 200000;

struct UF {
	int p[maxn];
	void init(int n) {
		fill(p, p + n, -1);
	}
	int get(int s) { return p[s] < 0 ? s : (p[s] = get(p[s])); }
	int sz(int s) { return -p[get(s)]; }
	bool unite(int a, int b) {
		a = get(a); b = get(b);
		if (a != b) {
			if (p[b] < p[a]) swap(a, b);
			p[a] += p[b];
			p[b] = a;
		}
		return a != b;
	}
} uf;

int a[maxn];
int n;

__gnu_pbds::gp_hash_table<int, int> h[30];

void Modify(int x, int y) {
	for (int j = 0; j < 30; ++j) {
		h[j][x] += y;
		x &= ~(1 << j);
	}
}

int Smallest(int i) {
	Modify(a[i], -1);
	int k = 0;
	for (int j = 29; j >= 0; --j) {
		if (h[j][k + (a[i] & (1 << j))]) k += a[i] & (1 << j);
		else k += (~a[i]) & (1 << j);
	}
	int j = lower_bound(a, a + n, k) - a;
	Modify(a[i], 1);
	return j;
}

int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin.exceptions(cin.failbit);

	cin >> n;
	uf.init(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		Modify(a[i], 1);
	}
	sort(a, a + n);
	for (int i = 0; i < n; ++i) {
		int j = Smallest(i);
		uf.unite(i, j);
	}
	int b = 0;
	for (int i = 0; i < n; ++i) {
		if (uf.sz(i) > uf.sz(b)) {
			b = uf.get(i);
		}
	}
	int r = 0;
	for (int i = 0; i < n; ++i) {
		int j = Smallest(i);
		if (uf.get(j) != uf.get(b)) {
			r++;
			Modify(a[i], -1);
		} else uf.unite(i, b);
	}
	cout << r << '\n';
}


#include <bits/extc++.h>
using namespace std;

const int maxn = 200000;

struct UF {
	int p[maxn];
	void init(int n) {
		fill(p, p + n, -1);
	}
	int get(int s) { return p[s] < 0 ? s : (p[s] = get(p[s])); }
	int sz(int s) { return -p[get(s)]; }
	bool unite(int a, int b) {
		a = get(a); b = get(b);
		if (a != b) {
			if (p[b] < p[a]) swap(a, b);
			p[a] += p[b];
			p[b] = a;
		}
		return a != b;
	}
} uf;

int a[maxn];
int n;

__gnu_pbds::gp_hash_table<int, int> h[30];

void Modify(int x, int y) {
	for (int j = 0; j < 30; ++j) {
		h[j][x] += y;
		x &= ~(1 << j);
	}
}

int Smallest(int i) {
	Modify(a[i], -1);
	int k = 0;
	for (int j = 29; j >= 0; --j) {
		if (h[j][k + (a[i] & (1 << j))]) k += a[i] & (1 << j);
		else k += (~a[i]) & (1 << j);
	}
	int j = lower_bound(a, a + n, k) - a;
	Modify(a[i], 1);
	return j;
}

int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin.exceptions(cin.failbit);

	cin >> n;
	uf.init(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		Modify(a[i], 1);
	}
	sort(a, a + n);
	for (int i = 0; i < n; ++i) {
		int j = Smallest(i);
		uf.unite(i, j);
	}
	int b = 0;
	for (int i = 0; i < n; ++i) {
		if (uf.sz(i) > uf.sz(b)) {
			b = uf.get(i);
		}
	}
	int r = 0;
	for (int i = 0; i < n; ++i) {
		int j = Smallest(i);
		if (uf.get(j) != b) {
			r++;
			Modify(a[i], -1);
		} else {
			uf.unite(i, b);
		}
	}
	cout << r << '\n';
}


#include <bits/extc++.h>
using namespace std;

const int maxn = 200000;

struct UF {
	int p[maxn];
	void init(int n) {
		fill(p, p + n, -1);
	}
	int get(int s) { return p[s] < 0 ? s : (p[s] = get(p[s])); }
	int sz(int s) { return -p[get(s)]; }
	bool unite(int a, int b) {
		a = get(a); b = get(b);
		if (a != b) {
			if (p[b] < p[a]) swap(a, b);
			p[a] += p[b];
			p[b] = a;
		}
		return a != b;
	}
} uf;

int a[maxn];
int n;

__gnu_pbds::gp_hash_table<int, int> h[30];

void Modify(int x, int y) {
	for (int j = 0; j < 30; ++j) {
		h[j][x] += y;
		x &= ~(1 << j);
	}
}

int Smallest(int i) {
	Modify(a[i], -1);
	int k = 0;
	for (int j = 29; j >= 0; --j) {
		if (h[j][k + (a[i] & (1 << j))]) k += a[i] & (1 << j);
		else k += (~a[i]) & (1 << j);
	}
	int j = lower_bound(a, a + n, k) - a;
	Modify(a[i], 1);
	return j;
}

int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin.exceptions(cin.failbit);

	cin >> n;
	uf.init(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		Modify(a[i], 1);
	}
	sort(a, a + n);
	for (int i = 0; i < n; ++i) {
		int j = Smallest(i);
		uf.unite(i, j);
	}
	int b = 0;
	for (int i = 0; i < n; ++i) {
		if (uf.sz(i) > uf.sz(b)) {
			b = uf.get(i);
		}
	}
	int r = 0;
	for (int i = 0; i < n; ++i) {
		int j = Smallest(i);
		if (uf.get(j) != uf.get(b)) {
			r++;
			Modify(a[i], -1);
		} else {
			uf.unite(i, j);
			uf.unite(j, b);
		}
	}
	cout << r << '\n';
}


#include <bits/extc++.h>
using namespace std;

const int maxn = 200000;

int a[maxn];
int n;

int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin.exceptions(cin.failbit);

	cin >> n;
	map<int, int> h;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		int j = 1 << 29;
		while (j && !(j & a[i])) j /= 2;
		h[j]++;
	}
	int r = 0, c = h.size();
	for (auto [a, b] : h) {
		if (h[0] && a > 0)
			r = max(r, b + c - 2);
		else
			r = max(r, b + c - 1);
	}
	cout << n - r << '\n';
}


#include <bits/extc++.h>
using namespace std;

const int maxn = 200000;

struct UF {
	int p[maxn];
	void init(int n) {
		fill(p, p + n, -1);
	}
	int get(int s) { return p[s] < 0 ? s : (p[s] = get(p[s])); }
	int sz(int s) { return -p[get(s)]; }
	bool unite(int a, int b) {
		a = get(a); b = get(b);
		if (a != b) {
			if (p[b] < p[a]) swap(a, b);
			p[a] += p[b];
			p[b] = a;
		}
		return a != b;
	}
} uf;

int a[maxn];
int n;

__gnu_pbds::gp_hash_table<int, int> h[30];

void mod(int x, int y) {
	for (int j = 0; j < 30; ++j) {
		h[j][x] += y;
		x &= ~(1 << j);
	}
}

int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin.exceptions(cin.failbit);

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		mod(a[i], 1);
	}
	uf.init(n);
	sort(a, a + n);
	for (int i = 0; i < n; ++i) {
		mod(a[i], -1);
		int k = 0;
		for (int j = 29; j >= 0; --j) {
			if (h[j][k + (a[i] & (1 << j))]) k += a[i] & (1 << j);
			else k += (~a[i]) & (1 << j);
		}
		int u = lower_bound(a, a + n, k) - a;
		assert(a[u] == k);
		uf.unite(i, u);
		mod(a[i], 1);
	}

	set<int> roots;
	for (int i = 0; i < n; ++i) roots.insert(uf.get(i));

	int l = 0, a = 0;
	for (int k : roots) {
		k = uf.sz(k);
		l = max(l, k);
		a += k - 1;
	}
	cout << a - l + 1 << '\n';
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 200005;

int tr[N*30][2], cnt[N*30];
int ne = 2;

const int LG = 29;

void add(int val, int to_add) {
	int p = 1;
	for(int b = LG; b >= 0; b--) {
		int c = val >> b & 1;
		if(!tr[p][c]) tr[p][c] = ne++;
		p = tr[p][c];
		cnt[p] += to_add;
	}
}

int solve(int p, int acc, int b) {
	if(!p) return acc;
	if(b == -1) return acc + 1;
	return max(
		solve(tr[p][0], acc + min(1, cnt[ tr[p][1] ]), b - 1),
		solve(tr[p][1], acc + min(1, cnt[ tr[p][0] ]), b - 1)
	);
}

int n, a[N];

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", a + i);

	for(int i = 0; i < n; i++) {
		add(a[i], 1);
	}

	printf("%d\n", n - solve(1, 0, LG));
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 200005;

int tr[N*30][2], cnt[N*30];
int ne = 2;

const int LG = 29;

void add(int val, int to_add) {
	int p = 1;
	for(int b = LG; b >= 0; b--) {
		int c = val >> b & 1;
		if(!tr[p][c]) tr[p][c] = ne++;
		p = tr[p][c];
		cnt[p] += to_add;
	}
}

int get(int val) {
	int p = 1;
	int ans = 0;
	for(int b = LG; b >= 0; b--) {
		int c = val >> b & 1;
		if(cnt[ tr[p][c] ]) {
			p = tr[p][c];
		}
		else {
			ans ^= 1 << b;
			p = tr[p][1 - c];
		}
	}
	return ans;
}

int p[N];
int f(int u) {
	return u == p[u] ? u : p[u] = f(p[u]);
}

int n, a[N];
int sz[N];

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", a + i);

	map<int, int> back;

	for(int i = 0; i < n; i++) {
		add(a[i], 1);
		p[i] = i;
		back[ a[i] ] = i;
	}

	for(int i = 0; i < n; i++) {
		add(a[i], -1);
		int to = get(a[i]) ^ a[i];
		to = back[to];
		p[f(i)] = f(to);
		// printf("%d -> %d\n", a[i], to);
		add(a[i], 1);
	}

	for(int i = 0; i < n; i++) sz[f(i)]++;

	int comp = 0;
	int mx = 0;
	int ans = 0;
	for(int i = 0; i < n; i++) if(f(i) == i) {
		comp++;
		ans += sz[i] - 1;
		mx = max(mx, sz[i] - 1);
	}

	printf("%d\n", ans - mx);
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 200005;

int tr[N*30][2], cnt[N*30];
int ne = 2;

const int LG = 29;

void add(int val, int to_add) {
	int p = 1;
	for(int b = LG; b >= 0; b--) {
		int c = val >> b & 1;
		if(!tr[p][c]) tr[p][c] = ne++;
		p = tr[p][c];
		cnt[p] += to_add;
	}
}

int solve(int p, int acc) {
	if(!p) return acc;
	return max(
		solve(tr[p][0], acc + min(1, cnt[ tr[p][1] ])),
		solve(tr[p][1], acc + min(1, cnt[ tr[p][0] ]))
	);
}

int n, a[N];

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", a + i);

	for(int i = 0; i < n; i++) {
		add(a[i], 1);
	}

	printf("%d\n", n - solve(1, 0) - 1);
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 200005;

int tr[N*30][2], cnt[N*30];
int ne = 2;

const int LG = 3;

void add(int val, int to_add) {
	int p = 1;
	for(int b = LG; b >= 0; b--) {
		int c = val >> b & 1;
		if(!tr[p][c]) tr[p][c] = ne++;
		p = tr[p][c];
		cnt[p] += to_add;
	}
}

int get(int val) {
	int p = 1;
	int ans = 0;
	for(int b = LG; b >= 0; b--) {
		int c = val >> b & 1;
		if(cnt[ tr[p][c] ]) {
			p = tr[p][c];
		}
		else {
			ans ^= 1 << b;
			p = tr[p][1 - c];
		}
	}
	return ans;
}

int p[N];
int f(int u) {
	return u == p[u] ? u : p[u] = f(p[u]);
}

int n, a[N];

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", a + i);

	map<int, int> back;

	for(int i = 0; i < n; i++) {
		add(a[i], 1);
		p[i] = i;
		back[ a[i] ] = i;
	}

	for(int i = 0; i < n; i++) {
		add(a[i], -1);
		int to = get(a[i]) ^ a[i];
		to = back[to];
		p[f(i)] = f(to);
		// printf("%d -> %d\n", a[i], to);
		add(a[i], 1);
	}

	int comp = 0;
	for(int i = 0; i < n; i++) if(f(i) == i) comp++;

	printf("%d\n", comp - 1);
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 200005;

int tr[N*30][2], cnt[N*30];
int ne = 2;

const int LG = 3;

void add(int val, int to_add) {
	int p = 1;
	for(int b = LG; b >= 0; b--) {
		int c = val >> b & 1;
		if(!tr[p][c]) tr[p][c] = ne++;
		p = tr[p][c];
		cnt[p] += to_add;
	}
}

int get(int val) {
	int p = 1;
	int ans = 0;
	for(int b = LG; b >= 0; b--) {
		int c = val >> b & 1;
		if(cnt[ tr[p][c] ]) {
			p = tr[p][c];
		}
		else {
			ans ^= 1 << b;
			p = tr[p][1 - c];
		}
	}
	return ans;
}

int p[N];
int f(int u) {
	return u == p[u] ? u : p[u] = f(p[u]);
}

int n, a[N];
int sz[N];

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", a + i);

	map<int, int> back;

	for(int i = 0; i < n; i++) {
		add(a[i], 1);
		p[i] = i;
		back[ a[i] ] = i;
	}

	for(int i = 0; i < n; i++) {
		add(a[i], -1);
		int to = get(a[i]) ^ a[i];
		to = back[to];
		p[f(i)] = f(to);
		// printf("%d -> %d\n", a[i], to);
		add(a[i], 1);
	}

	for(int i = 0; i < n; i++) sz[f(i)]++;

	int comp = 0;
	int mx = 0;
	int ans = 0;
	for(int i = 0; i < n; i++) if(f(i) == i) {
		comp++;
		ans += sz[i] - 1;
		mx = max(mx, sz[i] - 1);
	}

	printf("%d\n", ans - mx);
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int bitx[35];
int n,ara[200005];
int main()
{
	// cout << (1LL << 31) << endl;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&ara[i]);
	for(int i=0;i<n;i++)
	{
		int m = (1<<31);
		int p = 31;
		while(m)
		{
			if((m&ara[i]))
			{
				bitx[p+1]++;
				 // cout << p+1 << endl;
				break;
			}
			p--;
			m = m/2;
		}
		if(ara[i]==0)bitx[0]++;
	}
	int ans = 0;
	int hate = 0;
	int choto = n;
	for(int i=32;i>=0;i--)
	{
		choto = choto-bitx[i];
		if(choto==0)
		{
			ans = max(ans,bitx[i]+hate);
		}
		else if(choto)
		{
			ans = max(ans,bitx[i]+hate+1);
		}
		// else
		// {
		// 	ans = max(ans,1+bitx[i]+hate);
		// }
		hate += (bitx[i])?1:0;
	}
	printf("%d\n",n-ans);
}


#include<bits/stdc++.h>
using namespace std;
int c = 1;
int dp[40*200005],tr[40*200005][2];
int ara[200005];
void tin(int x)
{
	int v = 0;
	for(int i=31;i>=0;i--)
	{
		if(x&(1<<i))
		{
			if(!tr[v][1]) tr[v][1] = c++;
			v = tr[v][1];
		}
		else
		{
			if(!tr[v][0]) tr[v][0] = c++;
			v = tr[v][0];
		}
	}
	dp[v] = 1;
}
int call(int x)
{
	if(dp[x]!=-1)return dp[x];
	int ret = 0;
	if(tr[x][0] && tr[x][1])
	{
		ret = max(ret,1+call(tr[x][0]));
		ret = max(ret,1+call(tr[x][1]));
	}
	else
	{
		if(tr[x][0])
			ret = max(ret,call(tr[x][0]));
		else
			ret = max(ret,call(tr[x][1]));
	}
	return dp[x] = ret;
}
int main()
{
	memset(dp,-1,sizeof dp);
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",ara+i);
		tin(ara[i]);
	}
	printf("%d\n",n-call(0));
}


#include<bits/stdc++.h>
using namespace std;
int c = 1;
int dp[200005],tr[40*200005][2];
int ara[200005];
void tin(int x)
{
	int v = 0;
	for(int i=31;i>=0;i--)
	{
		if(x&(1<<i))
		{
			if(!tr[v][1]) tr[v][1] = c++;
			v = tr[v][1];
		}
		else
		{
			if(!tr[v][0]) tr[v][0] = c++;
			v = tr[v][0];
		}
	}
	dp[v] = 1;
}
int call(int x)
{
	if(dp[x]!=-1)return dp[x];
	int ret = 0;
	if(tr[x][0] && tr[x][1])
	{
		ret = max(ret,1+call(tr[x][0]));
		ret = max(ret,1+call(tr[x][1]));
	}
	else
	{
		if(tr[x][0])
			ret = max(ret,call(tr[x][0]));
		else
			ret = max(ret,call(tr[x][1]));
	}
	return dp[x] = ret;
}
int main()
{
	memset(dp,-1,sizeof dp);
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",ara+i);
		tin(ara[i]);
	}
	printf("%d\n",n-call(0));
}


#include<bits/stdc++.h>
using namespace std;
int c = 1;
int dp[200005],tr[4*200005][2];
int ara[200005];
void tin(int x)
{
	int v = 0;
	for(int i=31;i>=0;i--)
	{
		if(x&(1<<i))
		{
			if(!tr[v][1]) tr[v][1] = c++;
			v = tr[v][1];
		}
		else
		{
			if(!tr[v][0]) tr[v][0] = c++;
			v = tr[v][0];
		}
	}
	dp[v] = 1;
}
int call(int x)
{
	if(dp[x]!=-1)return dp[x];
	int ret = 0;
	if(tr[x][0] && tr[x][1])
	{
		ret = max(ret,1+call(tr[x][0]));
		ret = max(ret,1+call(tr[x][1]));
	}
	else
	{
		if(tr[x][0])
			ret = max(ret,call(tr[x][0]));
		else
			ret = max(ret,call(tr[x][1]));
	}
	return dp[x] = ret;
}
int main()
{
	memset(dp,-1,sizeof dp);
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",ara+i);
		tin(ara[i]);
	}
	printf("%d\n",n-call(0));
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 200010

int n, a[MAXN];
bool vis[MAXN];

void read(){
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", a + i);
}

void work(){
    int ans = 0;
    for(int k = 30; ~k; --k){
        int cnt0 = 0, cnt1 = 0;
        for(int i = 1; i <= n; ++i){
            if(vis[i]) continue;
            if(a[i] >> k & 1) ++cnt1;
            else ++cnt0;
        }
        ans += max(0, min(cnt0, cnt1) - 1);
        for(int i = 1; i <= n; ++i){
            if(vis[i]) continue;
            if(a[i] >> k & 1 && cnt0 > cnt1) vis[i] = true;
            if(a[i] >> k & 1 ^ 1 && cnt0 < cnt1) vis[i] = true;
        }
    }
    printf("%d\n", ans);
}

int main(){
    read();
    work();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 200010

int n, a[MAXN];
bool vis[MAXN];

void read(){
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", a + i);
}

void work(){
    int ans = 0;
    for(int k = 30; ~k; --k){
        int cnt0 = 0, cnt1 = 0;
        for(int i = 1; i <= n; ++i){
            if(vis[i]) continue;
            if(a[i] >> k & 1) ++cnt1;
            else ++cnt0;
        }
        ans += max(0, min(cnt0, cnt1) - 1);
        for(int i = 1; i <= n; ++i){
            if(vis[i]) continue;
            if(a[i] >> k & 1 && cnt0 > cnt1) vis[i] = true;
            if(a[i] >> k & 1 ^ 1 && cnt0 <= cnt1) vis[i] = true;
        }
    }
    printf("%d\n", ans);
}

int main(){
    read();
    work();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 200010

int n, a[MAXN];
bool vis[MAXN];

void read(){
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", a + i);
}

void work(){
    int ans = 0;
    for(int k = 30; ~k; --k){
        int cnt0 = 0, cnt1 = 0;
        for(int i = 1; i <= n; ++i){
            if(vis[i]) continue;
            if(a[i] & (1 << k)) ++cnt1;
            else ++cnt0;
        }
        ans += max(0, min(cnt0, cnt1) - 1);
        for(int i = 1; i <= n; ++i){
            if(vis[i]) continue;
            if(a[i] & 1 << k && cnt0 > cnt1) vis[i] = true;
            if(a[i] & 1 << k ^ 1 && cnt0 < cnt1) vis[i] = true;
        }
    }
    printf("%d\n", ans);
}

int main(){
    read();
    work();
    return 0;
}