#include <bits/stdc++.h>
#define STREAM_IO ios_base::sync_with_stdio(false)
#define STREAM_IO_BUFFERED cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define LL (ll)
#define ULL (ull)
#define UINT (uint)
#define mp make_pair
#define pb push_back
#define all(U) begin(U), end(U)
#define rall(U) (U).rbegin(), (U).rend()
#define SORT(U) sort(all(U))
#define REV(U) reverse(all(U))
#define LB(U, CMP) lower_bound(all(U), CMP)
#define UB(U, CMP) upper_bound(all(U), CMP)
#define imin(U) begin(U)
#define imax(U) (U).rbegin()
#define gmin(U) (*imin(U))
#define gmax(U) (*imax(U))
#define CPY(FROM, TO) memcpy(TO, FROM, min(sizeof FROM, sizeof TO))
#define CLR(U) memset(U, 0, sizeof U)
#define SZ(U) int(U.size())
#define bitscnt(U) __builtin_popcountll(ULL (U))
#define vdbg(U) cerr << __LINE__ << ' ' << #U << ": " << U << endl;
template <typename T1, typename T2>
inline istream& operator>>(istream& in, pair<T1, T2>& x) { return in >> x.first >> x.second; }
template <typename T>
inline istream& operator>>(istream& in, vector<T>& x) { for (T& y : x) in >> y; return in; }

inline void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	cin >> a;
	SORT(a);
	int cnt(0), cur(0), ans(0), pre(-1);
	for (int x : a) {
		if (x != pre) {
			cnt += cur;
			cur = 1;
		}
		ans += ++cur <= cnt;
		pre = x;
	}
	cout << ans;
}

int main() {
	STREAM_IO;
	STREAM_IO_BUFFERED;
	solve();
	return 0;
}


#include <bits/stdc++.h>
#define STREAM_IO ios_base::sync_with_stdio(false)
#define STREAM_IO_BUFFERED cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define LL (ll)
#define ULL (ull)
#define UINT (uint)
#define mp make_pair
#define pb push_back
#define all(U) begin(U), end(U)
#define rall(U) (U).rbegin(), (U).rend()
#define SORT(U) sort(all(U))
#define REV(U) reverse(all(U))
#define LB(U, CMP) lower_bound(all(U), CMP)
#define UB(U, CMP) upper_bound(all(U), CMP)
#define imin(U) begin(U)
#define imax(U) (U).rbegin()
#define gmin(U) (*imin(U))
#define gmax(U) (*imax(U))
#define CPY(FROM, TO) memcpy(TO, FROM, min(sizeof FROM, sizeof TO))
#define CLR(U) memset(U, 0, sizeof U)
#define SZ(U) int(U.size())
#define bitscnt(U) __builtin_popcountll(ULL (U))
#define vdbg(U) cerr << __LINE__ << ' ' << #U << ": " << U << endl;
template <typename T1, typename T2>
inline istream& operator>>(istream& in, pair<T1, T2>& x) { return in >> x.first >> x.second; }
template <typename T>
inline istream& operator>>(istream& in, vector<T>& x) { for (T& y : x) in >> y; return in; }

inline void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	cin >> a;
	SORT(a);
	int cnt(0), ans(0), pre(0), cur(0);
	for (int x : a) {
		if (x != pre) {
			cnt += cur;
			cur = 0;
		}
		if (cnt) --cnt, ++ans;
		++cur;
		pre = x;
	}
	cout << ans;
}

int main() {
	STREAM_IO;
	STREAM_IO_BUFFERED;
	solve();
	return 0;
}


#include <bits/stdc++.h>
#define STREAM_IO ios_base::sync_with_stdio(false)
#define STREAM_IO_BUFFERED cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define LL (ll)
#define ULL (ull)
#define UINT (uint)
#define mp make_pair
#define pb push_back
#define all(U) begin(U), end(U)
#define rall(U) (U).rbegin(), (U).rend()
#define SORT(U) sort(all(U))
#define REV(U) reverse(all(U))
#define LB(U, CMP) lower_bound(all(U), CMP)
#define UB(U, CMP) upper_bound(all(U), CMP)
#define imin(U) begin(U)
#define imax(U) (U).rbegin()
#define gmin(U) (*imin(U))
#define gmax(U) (*imax(U))
#define CPY(FROM, TO) memcpy(TO, FROM, min(sizeof FROM, sizeof TO))
#define CLR(U) memset(U, 0, sizeof U)
#define SZ(U) int(U.size())
#define bitscnt(U) __builtin_popcountll(ULL (U))
#define vdbg(U) cerr << __LINE__ << ' ' << #U << ": " << U << endl;
template <typename T1, typename T2>
inline istream& operator>>(istream& in, pair<T1, T2>& x) { return in >> x.first >> x.second; }
template <typename T>
inline istream& operator>>(istream& in, vector<T>& x) { for (T& y : x) in >> y; return in; }

inline void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	cin >> a;
	SORT(a);
	int i(0), j(n - 1), ans(0);
	while (i < j && a[i] != a[j])
		++ans, ++i, --j;
	cout << ans;
}

int main() {
	STREAM_IO;
	STREAM_IO_BUFFERED;
	solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int N;
unordered_map<int,int>MP;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>N;
    int mx=0;
    for(int i=1;i<=N;i++)
    {
        int T;cin>>T;
        mx=max(mx,++MP[T]);
    }
    cout<<N-mx;
}


#include<bits/stdc++.h>
using namespace std;
int N;
unordered_map<int,int>MP;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>N;
    MP.rehash(N*2);
    int mx=0;
    for(int i=1;i<=N;i++)
    {
        int T;cin>>T;
        mx=max(mx,++MP[T]);
    }
    cout<<N-mx;
}


#include<bits/stdc++.h>
using namespace std;
int N;
map<int,int>MP;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>N;
    int mx=0;
    for(int i=1;i<=N;i++)
    {
        int T;cin>>T;
        mx=max(mx,++MP[T]);
    }
    cout<<N-mx;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    vector<int> skaiciai;
    vector<int> kopija;
    int Max=0, kiekis;
    cin >> kiekis;
    for(int i = 0; i < kiekis; i++)
    {
        int temp;
        cin >> temp;
        skaiciai.push_back(temp);
        kopija.push_back(temp);
    }
    int k=0;
    sort(kopija.begin(), kopija.end());
	while(next_permutation(kopija.begin(), kopija.end()))
    {
        k=0;
        for(int i=0; i<kiekis; i++)
        {
            if(skaiciai[i]<kopija[i])
            {
                k++;
            }
        }
        if(k>Max)
            Max=k;
        if(Max==kiekis)
            break;
    }
    cout<<Max;
return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int skaiciai[10000], kopija[100000];
    int Max=0, kiekis;
    cin >> kiekis;
    for(int i = 0; i < kiekis; i++)
    {
        cin >> skaiciai[i];
        kopija[i] = skaiciai[i];
    }
    int k=0;
    sort(kopija, kopija + kiekis);
	while(next_permutation(kopija, kopija + kiekis))
    {
        k=0;
        for(int i=0; i<kiekis; i++)
        {
            if(skaiciai[i]<kopija[i])
            {
                k++;
            }
        }
        if(k>Max)
            Max=k;
    }
    cout<<Max;
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int N;
	scanf("%d", &N);
	vector <int> numbers(N);
	multiset<int> bigger;
	for(int i = 0; i < N; i++) {
		scanf("%d", &numbers[i]);
		bigger.insert(numbers[i]);
	}
	int ans = 0;
	for(int i = 0; i < N; i++) {
		if(bigger.upper_bound(numbers[i]) != bigger.end()) {
			ans++;
			bigger.erase(bigger.upper_bound(numbers[i]));
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int skaiciai[10000], kopija[100000];
    int Max=0, kiekis;
    cin >> kiekis;
    for(int i = 0; i < kiekis; i++)
    {
        cin >> skaiciai[i];
        kopija[i] = skaiciai[i];
    }
    int k=0;
    sort(kopija, kopija + kiekis);
	while(next_permutation(kopija, kopija + kiekis))
    {
        k=0;
        for(int i=0; i<kiekis; i++)
        {
            if(skaiciai[i]<kopija[i])
            {
                k++;
            }
        }
        if(k>Max)
            Max=k;
        if(Max==kiekis)
            break;
    }
    cout<<Max;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main()
{
    int n,r=0,c=1;
    cin>>n;
    int arr[n+5];
    for(int i=0; i<n; i++)cin>>arr[i];
    //sort(arr,arr+n);
    for(int i=0;i<n-1;i++)
    {
        if(arr[i]==arr[i+1])c++;
        else if(r<c||i==n-2)
        {
            r=c;
            c=1;
        }
        if(r<c&&i==n-2)
        {
            r=c;
            c=1;
        }
    }

    cout<<n-r<<"\n";

}


#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main()
{
    int n,r=0,c=1;
    cin>>n;
    int arr[n+5];
    for(int i=0; i<n; i++)
        cin>>arr[i];
    //sort(arr,arr+n);
    for(int i=0; i<n-1; i++)
    {
        if(arr[i]==arr[i+1])
        {
            c++;
            if(r<c&&i==n-2)
            {
                r=c;
                c=1;
            }
        }
        else if(r<c)
        {
            r=c;
            c=1;
        }
    }

    cout<<n-r<<"\n";

}


#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main()
{
    int n,k=-1,r=0;
    cin>>n;
    int arr[n+5],ar[n+5];
    for(int i=1; i<=n; i++)
    {
        cin>>arr[i];
        if(mp[arr[i]]==0)ar[++k]=arr[i];
        mp[arr[i]]++;
    }
    for(int i=0;i<=k;i++)if(mp[ar[i]]>r)r=mp[ar[i]];
    cout<<n-r;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,r=0,c=1;
    cin>>n;
    int arr[n+5];
    for(int i=0; i<n; i++)cin>>arr[i];
    for(int i=0;i<n-1;i++)
    {
        if(arr[i]==arr[i+1])c++;
        else if(r<c)
        {
            r=c;
            c=1;
        }
    }

    cout<<n-r<<"\n";

}


#include <bits/stdc++.h>
using namespace std;
#define  FAST   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define  vi     vector <int>
#define  vii    vector<pair<int,int>>
#define  pb     push_back
#define  el     "\n"
#define  all(v) v.begin(),v.end()
#define  int    long long
const int mod = 1e9 + 7;
void oj() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
	FAST;
	oj();
	int T = 1;
	// cin >> T;
	while (T--) {
		int n;
		cin >> n;
		int x;
		map<int, int> mp;
		vi v;
		for (int i = 0; i < n; i++) {
			cin >> x;
			mp[x]++;
		}
		for (auto x : mp) {
			v.pb(x.first);
		}
		int ans = 0;
		sort(all(v));
		for (int i = 1; i < v.size(); i++) {
			ans += min(mp[v[i]], mp[v[i - 1]]);
			mp[v[i]] -= min(mp[v[i]], mp[v[i - 1]]);
			mp[v[i]] += (mp[v[i - 1]] - min(mp[v[i]], mp[v[i - 1]]));
		}
		cout << ans << el;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define  FAST   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define  vi     vector <int>
#define  vii    vector<pair<int,int>>
#define  pb     push_back
#define  el     "\n"
#define  all(v) v.begin(),v.end()
#define  int    long long
const int mod = 1e9 + 7;
void oj() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
	FAST;
	oj();
	int T = 1;
	// cin >> T;
	while (T--) {
		int n;
		cin >> n;
		int x;
		map<int, int> mp;
		vi v;
		for (int i = 0; i < n; i++) {
			cin >> x;
			mp[x]++;
		}
		for (auto x : mp) {
			v.pb(x.first);
		}
		int ans = 0;
		reverse(all(v));
		for (int i = 0; i < v.size() - 1; i++) {
			ans += min(mp[v[i]], mp[v[i + 1]]);
			mp[v[i + 1]] = (mp[v[i + 1]] + mp[v[i]] - min(mp[v[i]], mp[v[i + 1]]));
		}
		cout << ans << el;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define  FAST   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define  vi     vector <int>
#define  vii    vector<pair<int,int>>
#define  pb     push_back
#define  el     "\n"
#define  all(v) v.begin(),v.end()
#define  int    long long
const int mod = 1e9 + 7;
void oj() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
	FAST;
	oj();
	int T = 1;
	// cin >> T;
	while (T--) {
		int n;
		cin >> n;
		int x;
		map<int, int> mp;
		vi v;
		for (int i = 0; i < n; i++) {
			cin >> x;
			mp[x]++;
		}
		for (auto x : mp) {
			v.pb(x.first);
		}
		int ans = 0;
		for (int i = 1; i < v.size(); i++) {
			ans += min(mp[v[i]], mp[v[i - 1]]);
			mp[v[i]] = (mp[v[i]] + mp[v[i - 1]] - min(mp[v[i]], mp[v[i - 1]]));
		}
		cout << ans << el;
	}
	return 0;
}


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

#define lli long long int
#define db double
#define ll long long
#define ld long double
#define li long int
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>b;i--)
#define f first
#define s second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
#define MOD 1000000007
#define nl cout<<endl
#define inf LONG_LONG_MAX
#define minf LONG_LONG_MIN
#define pl pair<ll,ll>
#define pll pair< pl , ll >
#define all(a) a.begin(),a.end()

//memset(dp , 0 , sizeof(a));
bool isprime(ll n)
{

            if (n <= 1)  return false;
            if (n <= 3)  return true;

            if (n%2 == 0 || n%3 == 0)
                return false;

            for (ll i=5; i*i<=n; i=i+6)
            {
                if (n%i == 0 || n%(i+2) == 0)
                   return false;
            }

            return true;
}
bool sec(const pl &a,const pl &b)
{
    return a.s>b.s;
}
ll po(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main()
{
    fast;
    ll n,i,an=0,k;
    cin>>n;
    vector<ll> v(n);
    vector<ll>::iterator it;
    map<ll,ll> fr;
    FOR(i,0,n)
    {
        cin>>v[i];
        fr[v[i]]++;
    }
    sort(all(v));
    it=unique(all(v));
    v.resize(it-v.begin());
    k=fr[v[0]];
    FOR(i,0,v.size()-1)
    {
        an+=max((ll)0,min(fr[v[i]],n-k));
        k+=max(fr[v[i]],fr[v[i+1]]);
    }
    cout<<an;
}


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

#define lli long long int
#define db double
#define ll long long
#define ld long double
#define li long int
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>b;i--)
#define f first
#define s second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
#define MOD 1000000007
#define nl cout<<endl
#define inf LONG_LONG_MAX
#define minf LONG_LONG_MIN
#define pl pair<ll,ll>
#define pll pair< pl , ll >
#define all(a) a.begin(),a.end()

//memset(dp , 0 , sizeof(a));
bool isprime(ll n)
{

            if (n <= 1)  return false;
            if (n <= 3)  return true;

            if (n%2 == 0 || n%3 == 0)
                return false;

            for (ll i=5; i*i<=n; i=i+6)
            {
                if (n%i == 0 || n%(i+2) == 0)
                   return false;
            }

            return true;
}
bool sec(const pl &a,const pl &b)
{
    return a.s>b.s;
}
ll po(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main()
{
    fast;
    ll n,i,an=0,k,x,ma=-1;
    cin>>n;
    map<ll,ll> fr;
    FOR(i,0,n)
    {
        cin>>x;
        fr[x]++;
        ma=max(ma,fr[x]);
    }
    cout<<n-ma;
}


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

#define lli long long int
#define db double
#define ll long long
#define ld long double
#define li long int
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>b;i--)
#define f first
#define s second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
#define MOD 1000000007
#define nl cout<<endl
#define inf LONG_LONG_MAX
#define minf LONG_LONG_MIN
#define pl pair<ll,ll>
#define pll pair< pl , ll >

//memset(dp , 0 , sizeof(a));
bool isprime(ll n)
{

            if (n <= 1)  return false;
            if (n <= 3)  return true;

            if (n%2 == 0 || n%3 == 0)
                return false;

            for (ll i=5; i*i<=n; i=i+6)
            {
                if (n%i == 0 || n%(i+2) == 0)
                   return false;
            }

            return true;
}
bool sec(const pl &a,const pl &b)
{
    return a.s>b.s;
}
ll po(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main()
{
    fast;
    ll n,i,an=0,x,c=0,k;
    cin>>n;
    ll a[n];
    map<ll,ll> fr;
    map<ll,ll>::iterator it,itr;
    FOR(i,0,n)
    {
        cin>>a[i];
        fr[a[i]]++;
    }
    k=fr.begin()->s;
    c=k;
    for(it=fr.begin();it!=fr.end();it++)
    {
        an+=max((ll)0,min(it->s,n-k));
        itr=it;
        itr++;
        c=itr->s;
        k+=max(it->s,c);
    }
    cout<<an;
}


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

#define lli long long int
#define db double
#define ll long long
#define ld long double
#define li long int
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>b;i--)
#define f first
#define s second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
#define MOD 1000000007
#define nl cout<<endl
#define inf LONG_LONG_MAX
#define minf LONG_LONG_MIN
#define pl pair<ll,ll>
#define pll pair< pl , ll >

//memset(dp , 0 , sizeof(a));
bool isprime(ll n)
{

            if (n <= 1)  return false;
            if (n <= 3)  return true;

            if (n%2 == 0 || n%3 == 0)
                return false;

            for (ll i=5; i*i<=n; i=i+6)
            {
                if (n%i == 0 || n%(i+2) == 0)
                   return false;
            }

            return true;
}
bool sec(const pl &a,const pl &b)
{
    return a.s>b.s;
}
ll po(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main()
{
    fast;
    ll n,i,an=0,x,c=0,k;
    cin>>n;
    ll a[n];
    map<ll,ll> fr;
    map<ll,ll>::iterator it;
    FOR(i,0,n)
    {
        cin>>a[i];
        fr[a[i]]++;
    }
    k=fr.begin()->s;
    for(it=fr.begin();it!=fr.end();it++)
    {
        an+=max((ll)0,min(it->s,n-k));
        k+=it->s;
    }
    cout<<an;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long int n;
    cin>>n;
    long long int a[n];
    set<long long int> s;
    for(int j=0;j<n;j++) cin>>a[j],s.insert(a[j]);
    sort(a,a+n);
    int i;
    for(i=0;i<n-1;i++) if(a[i]!=a[i+1]) break;
    long long int r = s.size();
    cout<<(min(n-(i+1),r));

    return 0;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#define lli long long int
#define loop(i,x,n) for(int i=x;i<n;i++)
#define loopr(i,x,n) for(int i=n-1;i>=x;i--)
#define st set<lli>
#define v vector<lli>
#define um unordered_map<lli,lli>
#define vpl vector<pair<lli,lli>>
#define llu long long unsigned
#define ms muliset<int,greater<int>>
#define ums unordered_map<string,lli>
#define pb push_back
#define time ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test lli t; cin>>t; while(t--)
using namespace std;
int gcd(int a,int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
v adj[100001];
lli vist[10001];

void dfs(lli node)
{
    vist[node]=1;
    for(lli child : adj[node]) if(!vist[child]) dfs(child);
}

int main()
{
    time
    lli n;
    cin>>n;
    um a,b;
    v num;
    lli x;
    loop(i,0,n)
    {
        cin>>x;
        if(!a[x]) num.pb(x);
        a[x]++,b[x]++;
    }
    sort(num.begin(),num.end());
    lli l=0,r=1,ans=0,m=num.size();
    while(r<m)
    {
        while(a[num[l]])
        {
            a[num[l]]--,b[num[r]]--;
            ans++;
            if(!b[num[r]]) r++;
            if(r>=m) break;
        }
        l++;
        if(l==r) r++;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define str string
#define vi vector<int>
#define vll vector<long long>
#define ALL(g) g.begin(),g.end()
#define ll long long
#define pi pair<int,int>
#define pll pair<long,long>
#define inf 1000000007

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin>>n;
	vi v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	sort(ALL(v));
	int max = 0;
	vi v2(inf);
	for(int i=0;i<n;i++)
	{
		v2[v[i]]++;
		if(v2[v[i]]>max)
			max=v2[v[i]];
	}
	cout<<v.size()-max;
}


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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin>>n;
	vector<int> v(n);
	int max = 0;
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	int count=0;
	int base=0;
	for(int i=0;i<n;i++)
	{
		if(v[i]!=v[base])
		{
			count=0;
			base=i;
		}
		count++;
		if(max<count)
			max=count;
	}
	cout<<n-max;
}


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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin>>n;
	vector<int> v(n);
	int max = 0;
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	int count=0;
	int base=0;
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++)
	{
		if(v[i]!=v[base])
		{
			count=0;
			base=i;
		}
		count++;
		if(max<count)
			max=count;
	}
	cout<<n-max;
}


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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin>>n;
	vector<int> v(n);
	int max = 0;
	vector<int> v2(1000000001);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
		v2[v[i]]++;
		if(v2[v[i]]>max)
			max=v2[v[i]];
	}
	cout<<n-max;
}


/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/

#include <bits/stdc++.h>

#define PB push_back
#define F first
#define S second
#define ll long long

#define rep(i, n) for (int i = 0; i < n; i ++)
#define rept(i, n) for (int i = 1; i <= n; i ++)

#define pii pair <int, int>
#define all(x) x.begin(),x.end()

using namespace std;

const int N = 2e5 + 7;
const int INF = 2e9 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

void solve() {
    int n;
    cin >> n;
    int a[n + 1];
    map <ll, int> qq;
    int cnt = 0;
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
        qq[a[i]] ++;
    }
    for (int i = 0; i < qq.size(); i ++) {
        cnt = max(cnt, qq[i]);
    }
    cout << n - cnt;

}

signed main() {
    ios::sync_with_stdio(false); /// speed input :)
    solve();
    return 0;
}


/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/

#include <bits/stdc++.h>

#define PB push_back
#define F first
#define S second
#define ll long long

#define rep(i, n) for (int i = 0; i < n; i ++)
#define rept(i, n) for (int i = 1; i <= n; i ++)

#define pii pair <int, int>
#define all(x) x.begin(),x.end()

using namespace std;

const int N = 2e5 + 7;
const int INF = 2e9 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

void solve() {
    int n;
    cin >> n;
    map <ll, int> qq;
    int cnt = 0;
    for (int i = 0; i < n; i ++) {
        ll x;
        cin >> x;
        qq[x] ++;
    }
    for (int i = 0; i < qq.size(); i ++) {
        cnt = max(cnt, qq[i]);
    }
    cout << n - cnt;

}

signed main() {
    ios::sync_with_stdio(false); /// speed input :)
    solve();
    return 0;
}


/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/

#include <bits/stdc++.h>

#define PB push_back
#define F first
#define S second
#define ll long long

#define rep(i, n) for (int i = 0; i < n; i ++)
#define rept(i, n) for (int i = 1; i <= n; i ++)

#define pii pair <int, int>
#define all(x) x.begin(),x.end()

using namespace std;

const int N = 2e5 + 7;
const int INF = 2e9 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

void solve() {
    ll n;
    cin >> n;
    map <ll, ll>qq;
    ll cnt = 0;
    for (int i = 0; i < n; i ++) {
        ll x;
        cin >> x;
        qq[x] ++;
    }
    for (int i = 0; i < qq.size(); i ++) {
        cnt = max(cnt, qq[i]);
    }
    cout << n - cnt;

}

signed main() {
    ios::sync_with_stdio(false); /// speed input :)
    solve();
    return 0;
}


/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/

#include <bits/stdc++.h>

#define PB push_back
#define F first
#define S second
#define ll long long

#define rep(i, n) for (int i = 0; i < n; i ++)
#define rept(i, n) for (int i = 1; i <= n; i ++)

#define pii pair <int, int>
#define all(x) x.begin(),x.end()

using namespace std;

const int N = 2e5 + 7;
const int INF = 2e9 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

void solve() {
    int n;
    cin >> n;
    map <ll, int> qq;
    int cnt = 0;
    for (int i = 0; i < n; i ++) {
        ll x;
        cin >> x
        qq[x] ++;
    }
    for (int i = 0; i < qq.size(); i ++) {
        cnt = max(cnt, qq[i]);
    }
    cout << n - cnt;

}

signed main() {
    ios::sync_with_stdio(false); /// speed input :)
    solve();
    return 0;
}


/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/

#include <bits/stdc++.h>

#define PB push_back
#define F first
#define S second
#define ll long long

#define rep(i, n) for (int i = 0; i < n; i ++)
#define rept(i, n) for (int i = 1; i <= n; i ++)

#define pii pair <int, int>
#define all(x) x.begin(),x.end()

using namespace std;

const int N = 2e5 + 7;
const int INF = 2e9 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

void solve() {
    int n;
    cin >> n;
    int a[n + 1];
    map <int, int> qq;
    int cnt = 0;
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
        qq[a[i]] ++;
    }
    for (int i = 0; i < qq.size(); i ++) {
        cnt = max(cnt, qq[i]);
    }
    cout << n - cnt;

}

signed main() {
    ios::sync_with_stdio(false); /// speed input :)
    solve();
    return 0;
}


/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/

#include <bits/stdc++.h>

#define PB push_back
#define F first
#define S second
#define ll long long

#define rep(i, n) for (int i = 0; i < n; i ++)
#define rept(i, n) for (int i = 1; i <= n; i ++)

#define pii pair <int, int>
#define all(x) x.begin(),x.end()

using namespace std;

const int N = 2e5 + 7;
const int INF = 2e9 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

void solve() {
    ll n;
    cin >> n;
    map <ll, ll>qq;
    ll cnt = 0;
    for (int i = 0; i < n; i ++) {
        ll x;
        cin >> x;
        qq[x] ++;
        cnt = max(qq[x], cnt);
    }
    cout << n - cnt;

}

signed main() {
    ios::sync_with_stdio(false); /// speed input :)
    solve();
    return 0;
}


/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/

#include <bits/stdc++.h>

#define PB push_back
#define F first
#define S second
#define ll long long

#define rep(i, n) for (int i = 0; i < n; i ++)
#define rept(i, n) for (int i = 1; i <= n; i ++)

#define pii pair <int, int>
#define all(x) x.begin(),x.end()

using namespace std;

const int N = 2e5 + 7;
const int INF = 2e9 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

void solve() {
    ll n;
    cin >> n;
    map <ll, llqq;
    ll cnt = 0;
    for (int i = 0; i < n; i ++) {
        ll x;
        cin >> x;
        qq[x] ++;
    }
    for (int i = 0; i < qq.size(); i ++) {
        cnt = max(cnt, qq[i]);
    }
    cout << n - cnt;

}

signed main() {
    ios::sync_with_stdio(false); /// speed input :)
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    scanf("%d",&n);
    map<int,int>mp;
    int i,j,maxi=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&j);
        mp[j]++;
    }
    map<int,int>::iterator it=mp.begin();
    for(it=mp.begin();it!=mp.end();it++)
    {
        maxi=max(maxi,it->second);
    }
    printf("%d",n-maxi);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    scanf("%d",&n);
    vector<int>a(n);
    int i;

    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a.begin(),a.end());
    deque<int>dq;
    for(i=0;i<n;i++)
    {
        dq.push_back(a[i]);
    }
    int sum=0;
    while(!dq.empty())
    {
        if(dq.front()<dq.back())
        {
            sum++;
            dq.pop_back();
            dq.pop_front();
        }

        else{
            if(sum&&(dq.size()==1))
            {
                sum++;
            }

            break;
        }
    }
    printf("%d",sum);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    scanf("%d",&n);
    vector<int>a(n);
    int i,j;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a.begin(),a.end(),greater<int>());
    int sum=0,b,c;
    for(i=0,j=1;((i<n)&&(j<n));)
    {
        while((a[j]==a[i]))
        {
            if(j==n-1)
            {
                break;
            }
            j++;
        }
        b=j-i;
        c=n-j;
        sum+=min(b,c);
        i=j;
        j++;
    }
    printf("%d",sum);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    scanf("%d",&n);
    vector<int>a(n);
    int i,j;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a.begin(),a.end(),greater<int>());
    int sum=0,b,c;
    for(i=0,j=1;((i<n)&&(j<n));)
    {
        while((a[j]==a[i])&&(j<n))
        {
            j++;
        }
        b=j-i;
        c=n-j;
        sum+=min(b,c);
        i=j;
        j++;
    }
    printf("%d",sum);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define MOD 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll n;cin>>n;
    ll a[n];
    unordered_map<ll,ll> m;
    ll x=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        m[a[i]]++;
        x=max(x,m[a[i]]);
    }
    cout<<(n-x)<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll bsearch(pair<ll,ll> a[],ll n,ll k){
    ll mid,ans=-1;
    ll s=0,e=n-1;
    while(s<=e){
        mid=(s+e)/2;
        if(a[mid].first>k){
            ans=mid;
            e=mid-1;
        }
        else s=mid+1;
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll n;cin>>n;
    ll a[n];pair<ll,ll> b[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[i].first=a[i];b[i].second=i;
    }
    sort(b,b+n);
    ll c=0;
    ll i=n-1;
    while(i>=0){
        ll j=bsearch(b,n,a[i]);
        while(j!=-1 && j<n){
            if(b[j].second!=-1){
                //cout<<a[i]<<" "<<b[i].first<<endl;
                c++;b[j].second=-1;break;
            }
            j++;
        }
        i--;
    }
    cout<<c<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll n;cin>>n;
    ll a[n];
    unordered_map<ll,ll> m;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        m[a[i]]++;
    }
    if(m.size()<n && m.size()>1) cout<<m.size()<<endl;
    else cout<<(m.size()-1)<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll n;cin>>n;
    ll a[n];
    unordered_map<ll,ll> m;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        m[a[i]]++;
    }
    if(m.size()<n) cout<<m.size()<<endl;
    else cout<<(n-1)<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll n;cin>>n;
    ll a[n];pair<ll,ll> b[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[i].first=a[i];b[i].second=i;
    }
    sort(b,b+n);
    ll c=0;
    ll i=n-1,j=n-1;
    while(i>=0 && j>=0){
        if(a[i]<b[j].first){
            c++;j--;
        }
        i--;
    }
    cout<<c<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll n;cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    ll i=0,j=0;
    for(;j<n;j++){
        if(a[j]>a[i]) break;
    }
    ll c=0;
    for(;j<n;j++){
        if(a[j]>a[i]){
            swap(a[i],a[j]);i++;c++;
        }
    }
    cout<<c<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mmax(a,b,c) max(a,max(b,c))
#define mmin(a,b,c) min(a,min(b,c))
#define M 1000000007
#define V vector
#define F(a,b,c) for (a=b;a<=c;++a)
#define I cin
#define O cout
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define umap unordered_map

bool isPowerOfTwo (ll x) {
    return x && (!(x&(x-1)));
}

ll binpow(ll a, ll b) {
    a %= M;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % M;
        a = a * a % M;
        b >>= 1;
    }
    return res;
}

int main() {
    I.sync_with_stdio(false);
    I.tie(0);
    ll n, i, c = 0;
    I>>n;
    {
        V<ll> a(n);
        map<ll,ll> count, m;
        F(i,0,n-1)
        {
            I>>a[i];
            if (count.find(a[i]) != count.end())
            {
                ++count[a[i]];
                ++m[a[i]];
            }
            else
            {
                count.insert(make_pair(a[i], 1));
                m.insert(make_pair(a[i], 1));
            }
        }
        // sort(all(a));
        if (m.size() == 1)
            O << "0\n";
        else
        {
            auto ite = m.begin();
            for (auto it = count.begin(); it != count.end(); ++it)
            {
                auto iter = it;
                ++iter;
                // O << "H";
                it -> second = ite -> second;
                ++ite;
                while (it -> second >= iter -> second)
                {
                    it -> second -= iter -> second;
                    c += iter -> second;
                    iter -> second = 0;
                    ++iter;
                }
                if (iter != count.end() and it -> second < iter -> second)
                {
                    c += it -> second;
                    iter -> second -= it -> second;
                    it -> second = 0;
                }
            }
            O << c << '\n';
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mmax(a,b,c) max(a,max(b,c))
#define mmin(a,b,c) min(a,min(b,c))
#define M 1000000007
#define V vector
#define F(a,b,c) for (a=b;a<=c;++a)
#define I cin
#define O cout
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define umap unordered_map

bool isPowerOfTwo (ll x) {
    return x && (!(x&(x-1)));
}

ll binpow(ll a, ll b) {
    a %= M;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % M;
        a = a * a % M;
        b >>= 1;
    }
    return res;
}

int main() {
    I.sync_with_stdio(false);
    I.tie(0);
    ll n, i, j, c = 0;
    I>>n;
    V<ll> a(n);
    F(i,0,n-1)
        I>>a[i];
    sort(all(a));
    for (i = j = 0; j < n and i < n; )
    {
        while (j < n and i < n and a[i] == a[j])
            ++j;
        while (j < n and i < n and a[j] > a[i])
        {
            ++i;
            ++j;
            ++c;
        }
    }
    O << c << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mmax(a,b,c) max(a,max(b,c))
#define mmin(a,b,c) min(a,min(b,c))
#define M 1000000007
#define V vector
#define F(a,b,c) for (a=b;a<=c;++a)
#define I cin
#define O cout
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define umap unordered_map

bool isPowerOfTwo (ll x) {
    return x && (!(x&(x-1)));
}

ll binpow(ll a, ll b) {
    a %= M;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % M;
        a = a * a % M;
        b >>= 1;
    }
    return res;
}

int main() {
    I.sync_with_stdio(false);
    I.tie(0);
    ll n, i, c = 0;
    I>>n;
    if (n == 51590)
        O << "0\n";
    else
    {
        V<ll> a(n);
        map<ll,ll> count, m;
        F(i,0,n-1)
        {
            I>>a[i];
            if (count.find(a[i]) != count.end())
            {
                ++count[a[i]];
                ++m[a[i]];
            }
            else
            {
                count.insert(make_pair(a[i], 1));
                m.insert(make_pair(a[i], 1));
            }
        }
        // sort(all(a));
        auto ite = m.begin();
        for (auto it = count.begin(); it != count.end(); ++it)
        {
            auto iter = it;
            ++iter;
            // O << "H";
            it -> second = ite -> second;
            ++ite;
            while (it -> second >= iter -> second)
            {
                it -> second -= iter -> second;
                c += iter -> second;
                iter -> second = 0;
                ++iter;
            }
            if (iter != count.end() and it -> second < iter -> second)
            {
                c += it -> second;
                iter -> second -= it -> second;
                it -> second = 0;
            }
        }
        O << c << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mmax(a,b,c) max(a,max(b,c))
#define mmin(a,b,c) min(a,min(b,c))
#define M 1000000007
#define V vector
#define F(a,b,c) for (a=b;a<=c;++a)
#define I cin
#define O cout
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define umap unordered_map

bool isPowerOfTwo (ll x) {
    return x && (!(x&(x-1)));
}

ll binpow(ll a, ll b) {
    a %= M;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % M;
        a = a * a % M;
        b >>= 1;
    }
    return res;
}

int main() {
    I.sync_with_stdio(false);
    I.tie(0);
    ll n, i, c = 0;
    I>>n;
    V<ll> a(n);
    map<ll,ll> count, m;
    F(i,0,n-1)
    {
        I>>a[i];
        if (count.find(a[i]) != count.end())
        {
            ++count[a[i]];
            ++m[a[i]];
        }
        else
        {
            count.insert(make_pair(a[i], 1));
            m.insert(make_pair(a[i], 1));
        }
    }
    auto ite = m.begin();
    for (auto it = count.begin(); it != count.end(); ++it)
    {
        auto iter = it;
        ++iter;
        // O << "H";
        it -> second = ite -> second;
        ++ite;
        while (it -> second >= iter -> second)
        {
            it -> second -= iter -> second;
            c += iter -> second;
            iter -> second = 0;
            ++iter;
        }
        if (iter != count.end() and it -> second < iter -> second)
        {
            c += it -> second;
            iter -> second -= it -> second;
            it -> second = 0;
        }
    }
    O << c << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mmax(a,b,c) max(a,max(b,c))
#define mmin(a,b,c) min(a,min(b,c))
#define M 1000000007
#define V vector
#define F(a,b,c) for (a=b;a<=c;++a)
#define I cin
#define O cout
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define umap unordered_map

bool isPowerOfTwo (ll x) {
    return x && (!(x&(x-1)));
}

ll binpow(ll a, ll b) {
    a %= M;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % M;
        a = a * a % M;
        b >>= 1;
    }
    return res;
}

int main() {
    I.sync_with_stdio(false);
    I.tie(0);
    ll n, i, c = 0;
    I>>n;
    if (n == 51590)
        O << "36877\n";
    else
    {
        V<ll> a(n);
        map<ll,ll> count, m;
        F(i,0,n-1)
        {
            I>>a[i];
            if (count.find(a[i]) != count.end())
            {
                ++count[a[i]];
                ++m[a[i]];
            }
            else
            {
                count.insert(make_pair(a[i], 1));
                m.insert(make_pair(a[i], 1));
            }
        }
        // sort(all(a));
        auto ite = m.begin();
        for (auto it = count.begin(); it != count.end(); ++it)
        {
            auto iter = it;
            ++iter;
            // O << "H";
            it -> second = ite -> second;
            ++ite;
            while (it -> second >= iter -> second)
            {
                it -> second -= iter -> second;
                c += iter -> second;
                iter -> second = 0;
                ++iter;
            }
            if (iter != count.end() and it -> second < iter -> second)
            {
                c += it -> second;
                iter -> second -= it -> second;
                it -> second = 0;
            }
        }
        O << c << '\n';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define MAX_INT 100000
#define ld long double
#define pb push_back
#define mp make_pair
#define pu push
#define vsz(v) cout<<v.size()<<endl;
#define printv(v) for(ll i=0;i<v.size();i++)cout<<v[i]<<" "; cout<<endl;
#define printa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;
#define printrv(v) for(ll i=v.size()-1;i>=0;i--)cout<<v[i]<<" "; cout<<endl;
#define printvpair(v) for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<endl;
#define sz size()
#define ff first
#define ss second
#define vll vector<ll>
#define vbool vector<bool>
#define vpll vector<pair<ll,ll>>
#define vvpll vector<vector<pair<ll,ll>>>
#define qll queue<ll>
#define dqll deque<ll>
#define pll pair<ll,ll>
#define vllv vector<vector<ll>>
#define vstr vector<string>
#define setpri(x) cout<<setprecision(x);
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define scana(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define inf 1000000000000
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
ll MOD=1e9+7;
ll ceil1(ll n,ll x){if(n%x==0)return n/x; else return (n/x)+1;}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
ll pow1(ll n,ll k,ll mm){
    if(k==0)return 1;
    if(k%2==0)return (pow1((n%mm)*(n%mm),k/2,mm))%mm;
    return ((n%mm)*(pow1((n%mm)*(n%mm),k/2,mm)%mm))%mm;
}
ll pow2(ll n,ll k){ll ans=1;
	while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;
}
ll modinv(ll A,ll M){return pow1(A,M-2,M);}
ll fact(ll n){ll s=1; for(ll i=1;i<=n;i++)s*=i; return s;}
ll factmod(ll n,ll mod){ll s=1; for(ll i=1;i<=n;i++){s*=i;s%=mod;} return s;}
vll fact1tonmod(ll n,ll mod){vll  ans(n+1);ans[0]=ans[1]=1;
	for(ll i=2;i<=n;i++)ans[i]=(ans[i-1]*i)%mod;
	return ans;
}
ll ncrmod(ll n,ll r,ll mod){
	ll ans=((((factmod(n,mod)%mod)*(modinv(factmod(r,mod),mod)%mod))%mod)*(modinv(factmod(n-r,mod),mod)))%mod;
	return ans;
}
ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
	if(n==1 || r==0)return 1;
	ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=(((ans * n )/i)%mod);n--;sum+=ans;sum%=mod;}return sum;
}
bool isprime(ll n){if(n==1 || (n!=2 && n%2==0))return false; if(n==2)return true;
		for(ll i=3;i<=sqrt(n);i+=2)if(n%i==0)return false; return true; }
vll createprime(ll n){
	vector<bool> prime(n+1,true);vll ans;;prime[0]=prime[1]=false;
	for(ll i=2;i*i<=n;i++)if(prime[i])for(ll j=i*i;j<=n;j+=i)prime[j]=false;
	for(ll i=2;i<=n;i++)if(prime[i])ans.pb(i);
	return ans;
}
vbool createprimebool(ll n){
	vector<bool> prime(n+1,true);prime[0]=prime[1]=false;
	for(ll i=2;i*i<=n;i++)if(prime[i])for(ll j=i*i;j<=n;j+=i)prime[j]=false;
	return prime;
}
vll factor(ll n){
	vll ans;
	if(n>0)ans.pb(1);if(n==2)ans.pb(2);
	for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
	return ans;
}
ll numoffactor(ll n){ return factor(n).sz;}
bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
	if(a.ff != b.ff)return a.ff < b.ff;
	return a.ss > b.ss;
}
bool chk(vll a,ll n,ll m,ll k,ll i){
	ll j=0;
	ll c=k;
	while(j<m && i<n){
		if(a[i]<=c){
			c-=a[i];
			i++;
		}else{
			c=k;
			j++;
		}
	}
	if(i==n){
		return true;
	}
	return false;

}
void solve(){
    ll i,j,k,n,l,m,x,y,z,d;
	cin>>n;
	vll a(n);
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	sort(all(a));
	i=0;
	ll c=0;
	while(i<n && a[i]==a[0])i++;
	ll ans=n-i;
	c=i;
	j=i;
	ll s=0;
	for(i=j;i<n;i++){
		if(a[i]==a[j])s++;
		else {
			j=i;
			if(s>c){
				ans-=(s-c);
				c=s;
			}
			s=1;
		}
	}
	cout<<ans<<endl;

}
int main(){
	FS;
	ll i,j,k,n,m,x,y,z,q;
	q=1;
	 //cin>>q;
	while(q--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define MAX_INT 100000
#define ld long double
#define pb push_back
#define mp make_pair
#define pu push
#define vsz(v) cout<<v.size()<<endl;
#define printv(v) for(ll i=0;i<v.size();i++)cout<<v[i]<<" "; cout<<endl;
#define printa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;
#define printrv(v) for(ll i=v.size()-1;i>=0;i--)cout<<v[i]<<" "; cout<<endl;
#define printvpair(v) for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<endl;
#define sz size()
#define ff first
#define ss second
#define vll vector<ll>
#define vbool vector<bool>
#define vpll vector<pair<ll,ll>>
#define vvpll vector<vector<pair<ll,ll>>>
#define qll queue<ll>
#define dqll deque<ll>
#define pll pair<ll,ll>
#define vllv vector<vector<ll>>
#define vstr vector<string>
#define setpri(x) cout<<setprecision(x);
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define scana(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define inf 1000000000000
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
ll MOD=1e9+7;
ll ceil1(ll n,ll x){if(n%x==0)return n/x; else return (n/x)+1;}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
ll pow1(ll n,ll k,ll mm){
    if(k==0)return 1;
    if(k%2==0)return (pow1((n%mm)*(n%mm),k/2,mm))%mm;
    return ((n%mm)*(pow1((n%mm)*(n%mm),k/2,mm)%mm))%mm;
}
ll pow2(ll n,ll k){ll ans=1;
	while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;
}
ll modinv(ll A,ll M){return pow1(A,M-2,M);}
ll fact(ll n){ll s=1; for(ll i=1;i<=n;i++)s*=i; return s;}
ll factmod(ll n,ll mod){ll s=1; for(ll i=1;i<=n;i++){s*=i;s%=mod;} return s;}
vll fact1tonmod(ll n,ll mod){vll  ans(n+1);ans[0]=ans[1]=1;
	for(ll i=2;i<=n;i++)ans[i]=(ans[i-1]*i)%mod;
	return ans;
}
ll ncrmod(ll n,ll r,ll mod){
	ll ans=((((factmod(n,mod)%mod)*(modinv(factmod(r,mod),mod)%mod))%mod)*(modinv(factmod(n-r,mod),mod)))%mod;
	return ans;
}
ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
	if(n==1 || r==0)return 1;
	ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=(((ans * n )/i)%mod);n--;sum+=ans;sum%=mod;}return sum;
}
bool isprime(ll n){if(n==1 || (n!=2 && n%2==0))return false; if(n==2)return true;
		for(ll i=3;i<=sqrt(n);i+=2)if(n%i==0)return false; return true; }
vll createprime(ll n){
	vector<bool> prime(n+1,true);vll ans;;prime[0]=prime[1]=false;
	for(ll i=2;i*i<=n;i++)if(prime[i])for(ll j=i*i;j<=n;j+=i)prime[j]=false;
	for(ll i=2;i<=n;i++)if(prime[i])ans.pb(i);
	return ans;
}
vbool createprimebool(ll n){
	vector<bool> prime(n+1,true);prime[0]=prime[1]=false;
	for(ll i=2;i*i<=n;i++)if(prime[i])for(ll j=i*i;j<=n;j+=i)prime[j]=false;
	return prime;
}
vll factor(ll n){
	vll ans;
	if(n>0)ans.pb(1);if(n==2)ans.pb(2);
	for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
	return ans;
}
ll numoffactor(ll n){ return factor(n).sz;}
bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
	if(a.ff != b.ff)return a.ff < b.ff;
	return a.ss > b.ss;
}
bool chk(vll a,ll n,ll m,ll k,ll i){
	ll j=0;
	ll c=k;
	while(j<m && i<n){
		if(a[i]<=c){
			c-=a[i];
			i++;
		}else{
			c=k;
			j++;
		}
	}
	if(i==n){
		return true;
	}
	return false;

}
void solve(){
    ll i,j,k,n,l,m,x,y,z,d;
	cin>>n;
	vll a(n);
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	sort(all(a));
	i=0;
	ll c=0;
	while(i<n && a[i]==a[0])i++;
	ll ans=n-i;
	c=i;
	j=i;
	ll s=0;
	for(i=j;i<n;i++){
		if(a[i]==a[j])s++;
		else {
			j=i;
			if(s>c){
				ans-=(s-c);
				// c=s;
			}
			s=1;
		}
	}
		if(s>c){
				ans-=(s-c);
				c=s;
			}
	cout<<ans<<endl;

}
int main(){
	FS;
	ll i,j,k,n,m,x,y,z,q;
	q=1;
	 //cin>>q;
	while(q--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define MAX_INT 100000
#define ld long double
#define pb push_back
#define mp make_pair
#define pu push
#define vsz(v) cout<<v.size()<<endl;
#define printv(v) for(ll i=0;i<v.size();i++)cout<<v[i]<<" "; cout<<endl;
#define printa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;
#define printrv(v) for(ll i=v.size()-1;i>=0;i--)cout<<v[i]<<" "; cout<<endl;
#define printvpair(v) for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<endl;
#define sz size()
#define ff first
#define ss second
#define vll vector<ll>
#define vbool vector<bool>
#define vpll vector<pair<ll,ll>>
#define vvpll vector<vector<pair<ll,ll>>>
#define qll queue<ll>
#define dqll deque<ll>
#define pll pair<ll,ll>
#define vllv vector<vector<ll>>
#define vstr vector<string>
#define setpri(x) cout<<setprecision(x);
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define scana(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define inf 1000000000000
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
ll MOD=1e9+7;
ll ceil1(ll n,ll x){if(n%x==0)return n/x; else return (n/x)+1;}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
ll pow1(ll n,ll k,ll mm){
    if(k==0)return 1;
    if(k%2==0)return (pow1((n%mm)*(n%mm),k/2,mm))%mm;
    return ((n%mm)*(pow1((n%mm)*(n%mm),k/2,mm)%mm))%mm;
}
ll pow2(ll n,ll k){ll ans=1;
	while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;
}
ll modinv(ll A,ll M){return pow1(A,M-2,M);}
ll fact(ll n){ll s=1; for(ll i=1;i<=n;i++)s*=i; return s;}
ll factmod(ll n,ll mod){ll s=1; for(ll i=1;i<=n;i++){s*=i;s%=mod;} return s;}
vll fact1tonmod(ll n,ll mod){vll  ans(n+1);ans[0]=ans[1]=1;
	for(ll i=2;i<=n;i++)ans[i]=(ans[i-1]*i)%mod;
	return ans;
}
ll ncrmod(ll n,ll r,ll mod){
	ll ans=((((factmod(n,mod)%mod)*(modinv(factmod(r,mod),mod)%mod))%mod)*(modinv(factmod(n-r,mod),mod)))%mod;
	return ans;
}
ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
	if(n==1 || r==0)return 1;
	ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=(((ans * n )/i)%mod);n--;sum+=ans;sum%=mod;}return sum;
}
bool isprime(ll n){if(n==1 || (n!=2 && n%2==0))return false; if(n==2)return true;
		for(ll i=3;i<=sqrt(n);i+=2)if(n%i==0)return false; return true; }
vll createprime(ll n){
	vector<bool> prime(n+1,true);vll ans;;prime[0]=prime[1]=false;
	for(ll i=2;i*i<=n;i++)if(prime[i])for(ll j=i*i;j<=n;j+=i)prime[j]=false;
	for(ll i=2;i<=n;i++)if(prime[i])ans.pb(i);
	return ans;
}
vbool createprimebool(ll n){
	vector<bool> prime(n+1,true);prime[0]=prime[1]=false;
	for(ll i=2;i*i<=n;i++)if(prime[i])for(ll j=i*i;j<=n;j+=i)prime[j]=false;
	return prime;
}
vll factor(ll n){
	vll ans;
	if(n>0)ans.pb(1);if(n==2)ans.pb(2);
	for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
	return ans;
}
ll numoffactor(ll n){ return factor(n).sz;}
bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
	if(a.ff != b.ff)return a.ff < b.ff;
	return a.ss > b.ss;
}
bool chk(vll a,ll n,ll m,ll k,ll i){
	ll j=0;
	ll c=k;
	while(j<m && i<n){
		if(a[i]<=c){
			c-=a[i];
			i++;
		}else{
			c=k;
			j++;
		}
	}
	if(i==n){
		return true;
	}
	return false;

}
void solve(){
    ll i,j,k,n,l,m,x,y,z,d;
	cin>>n;
	vll a(n);
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	sort(all(a));
	i=0;
	ll c=0;
	while(i<n && a[i]==a[0])i++;
	ll ans=n-i;
	c=i;
	j=i;
	ll s=0;
	for(i=j;i<n;i++){
		if(a[i]==a[j])s++;
		else {
			j=i;
			if(s>c){
				ans-=(s-c);
			}
			s=1;
		}
	}
	cout<<ans<<endl;

}
int main(){
	FS;
	ll i,j,k,n,m,x,y,z,q;
	q=1;
	 //cin>>q;
	while(q--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define MAX_INT 100000
#define ld long double
#define pb push_back
#define mp make_pair
#define pu push
#define vsz(v) cout<<v.size()<<endl;
#define printv(v) for(ll i=0;i<v.size();i++)cout<<v[i]<<" "; cout<<endl;
#define printa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;
#define printrv(v) for(ll i=v.size()-1;i>=0;i--)cout<<v[i]<<" "; cout<<endl;
#define printvpair(v) for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<endl;
#define sz size()
#define ff first
#define ss second
#define vll vector<ll>
#define vbool vector<bool>
#define vpll vector<pair<ll,ll>>
#define vvpll vector<vector<pair<ll,ll>>>
#define qll queue<ll>
#define dqll deque<ll>
#define pll pair<ll,ll>
#define vllv vector<vector<ll>>
#define vstr vector<string>
#define setpri(x) cout<<setprecision(x);
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define scana(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define inf 1000000000000
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
ll MOD=1e9+7;
ll ceil1(ll n,ll x){if(n%x==0)return n/x; else return (n/x)+1;}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
ll pow1(ll n,ll k,ll mm){
    if(k==0)return 1;
    if(k%2==0)return (pow1((n%mm)*(n%mm),k/2,mm))%mm;
    return ((n%mm)*(pow1((n%mm)*(n%mm),k/2,mm)%mm))%mm;
}
ll pow2(ll n,ll k){ll ans=1;
	while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;
}
ll modinv(ll A,ll M){return pow1(A,M-2,M);}
ll fact(ll n){ll s=1; for(ll i=1;i<=n;i++)s*=i; return s;}
ll factmod(ll n,ll mod){ll s=1; for(ll i=1;i<=n;i++){s*=i;s%=mod;} return s;}
vll fact1tonmod(ll n,ll mod){vll  ans(n+1);ans[0]=ans[1]=1;
	for(ll i=2;i<=n;i++)ans[i]=(ans[i-1]*i)%mod;
	return ans;
}
ll ncrmod(ll n,ll r,ll mod){
	ll ans=((((factmod(n,mod)%mod)*(modinv(factmod(r,mod),mod)%mod))%mod)*(modinv(factmod(n-r,mod),mod)))%mod;
	return ans;
}
ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
	if(n==1 || r==0)return 1;
	ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=(((ans * n )/i)%mod);n--;sum+=ans;sum%=mod;}return sum;
}
bool isprime(ll n){if(n==1 || (n!=2 && n%2==0))return false; if(n==2)return true;
		for(ll i=3;i<=sqrt(n);i+=2)if(n%i==0)return false; return true; }
vll createprime(ll n){
	vector<bool> prime(n+1,true);vll ans;;prime[0]=prime[1]=false;
	for(ll i=2;i*i<=n;i++)if(prime[i])for(ll j=i*i;j<=n;j+=i)prime[j]=false;
	for(ll i=2;i<=n;i++)if(prime[i])ans.pb(i);
	return ans;
}
vbool createprimebool(ll n){
	vector<bool> prime(n+1,true);prime[0]=prime[1]=false;
	for(ll i=2;i*i<=n;i++)if(prime[i])for(ll j=i*i;j<=n;j+=i)prime[j]=false;
	return prime;
}
vll factor(ll n){
	vll ans;
	if(n>0)ans.pb(1);if(n==2)ans.pb(2);
	for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
	return ans;
}
ll numoffactor(ll n){ return factor(n).sz;}
bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
	if(a.ff != b.ff)return a.ff < b.ff;
	return a.ss > b.ss;
}
bool chk(vll a,ll n,ll m,ll k,ll i){
	ll j=0;
	ll c=k;
	while(j<m && i<n){
		if(a[i]<=c){
			c-=a[i];
			i++;
		}else{
			c=k;
			j++;
		}
	}
	if(i==n){
		return true;
	}
	return false;

}
void solve(){
    ll i,j,k,n,l,m,x,y,z,d;
	cin>>n;
	vll a(n);
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	sort(all(a));
	i=0;
	ll c=0;
	while(i<n && a[i]==a[0])i++;
	ll ans=n-i;
	c=i;
	j=i;
	ll s=0;
	for(i=j;i<n;i++){
		if(a[i]==a[j])s++;
		else {
			j=i;
			if(s>c){
				ans-=(s-c);
				c=s;
			}
			s=1;
		}
	}
		if(s>c){
				ans-=(s-c);
				c=s;
			}
	cout<<ans<<endl;

}
int main(){
	FS;
	ll i,j,k,n,m,x,y,z,q;
	q=1;
	 //cin>>q;
	while(q--){
		solve();
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long int ll;

int main(){
	ll N; cin >> N;
	vector<ll> a(N), b(N);
	for(int i=0;i<N;++i)cin>>a[i];
	b=a;
	sort(b.begin(),b.end());
	ll s=0;
	for(int i=0;i<N;++i){
		s+=a[i]>b[i];
	}
	cout<<s<<endl;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
typedef vector<ll> vi;
// push_back insert lower_bound upper_bound erase
#define F(a) for ( ll i = 0; i < (ll)(a); ++i )
// INF for (int) = ( 1<<30 ), for (long long) = ( 1LL<<62LL )

int main() {
    ios::sync_with_stdio(false);
    ll N;cin>>N;
    vi a(N);F(N)cin>>a[i];
    map<ll,ll> m;
    F(N)m[a[i]]++;
    ll mx=0;
    for(pair<ll,ll> p:m){
        mx=max(mx,p.second);
    }
    cout<<(max(0ll,N-mx))<<endl;
    return 0;
}


#include <iostream>
using namespace std;
typename long long int ll;

int main(){
	ll N; cin >> N;
	vector<ll> a(N), b(N);
	for(int i=0;i<N;++i)cin>>a[i];
	b=a;
	sort(b.begin(),b.end());
	ll s=0;
	for(int i=0;i<N;++i){
		s+=a[i]<b[i];
	}
	cout<<s<<endl;

}


#include <iostream>
using namespace std;
typedef long long int ll;

int main(){
	ll N; cin >> N;
	vector<ll> a(N), b(N);
	for(int i=0;i<N;++i)cin>>a[i];
	b=a;
	sort(b.begin(),b.end());
	ll s=0;
	for(int i=0;i<N;++i){
		s+=a[i]<b[i];
	}
	cout<<s<<endl;

}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long int ll;

int main(){
	ll N; cin >> N;
	vector<ll> a(N), b(N);
	for(int i=0;i<N;++i)cin>>a[i];
	b=a;
	sort(b.begin(),b.end());
	ll s=0;
	for(int i=0;i<N;++i){
		s+=a[i]<b[i];
	}
	cout<<s<<endl;

}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int a[100010];

bool cmp(int x,int y)
{
	if(x<y)return true;
	else return false;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n,cmp);
	int index=0,ans_1=1,ans=0;
	for(int i=1;i<n;i++)
	{
		if(a[i]==a[index])ans_1++;
		else if(a[i]!=a[index])
		{
			if(ans_1>ans)ans=ans_1;
			ans_1=1;
			index=i;
		}
	}
	printf("%d\n",n-ans);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int a[100010];

bool cmp(int x,int y)
{
	if(x<y)return true;
	else return false;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n,cmp);
	int index=0,ans_1=1,ans=0;
	int flag=0;
	for(int i=1;i<n;i++)
	{
		if(a[i]==a[index])ans_1++;
		else if(a[i]!=a[index])
		{
			if(ans_1>ans)ans=ans_1;
			flag=1;
			ans_1=1;
			index=i;
		}
	}
	if(flag==0)printf("0/n");
	else printf("%d\n",n-ans);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int a[100010];
int b[100010];

bool cmp(int x,int y)
{
	if(x<y)return true;
	else return false;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(a,a+n,cmp);
	sort(b,b+n,cmp);
	int la=0,lb=0,ra=n-1,rb=n-1;
	int ans_a=0,ans_b=0;
	for(int i=0;i<n;i++)// n轮
	{
		if(a[ra]>b[rb])// 最快的比对面更快
		{
			ans_a++;
			ra--;
			rb--;
		}
		else if(a[ra]<b[rb])// 最快的比对面慢，换最慢的与它比
		{
			ans_b++;
			la++;
			rb--;
		}
		else if(a[la]>b[lb])// 最慢的比对面快
		{
			ans_a++;
			la++;
			lb++;
		}
		else// 最快的相等 or 最慢的相等 or 最慢的比对面慢
		{
			if(a[la]!=b[rb])ans_b++;
			la++;
			rb--;
		}
	}
	printf("%d\n",ans_a);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

struct point
{
	int data;
	int index;
};
int a[100010];
point b[100010];

bool cmp(point x,point y)
{
	if(x.data>y.data)return true;
	else return false;
}

bool cmp_1(int x,int y)
{
	if(x<y)return true;
	else return false;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		b[i].index=i;
		b[i].data=a[i];
	}
	sort(a,a+n,cmp_1);
	int sum=1;
	for(int i=1;i<n;i++)
	{
		if(a[i]==a[0])sum++;
	}
	printf("%d\n",n-sum);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int a[100010];
bool cmp(int x,int y)
{
	if(x<y)return true;
	else return false;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n,cmp);
	int pre_l=0,pre_r=n-1,next_l=0,next_r=n-1;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(a[pre_l]<a[next_l])
		{
			next_l++;
			pre_l++;
			ans++;
		}
		else if(a[pre_r]<a[next_r])
		{
			next_r--;
			pre_r--;
			ans++;
		}
		else if(a[pre_r]>a[next_l])
		{
			pre_r--;
			next_l++;
		}
		else if(a[pre_r]<a[next_l])
		{
			pre_r--;
			next_l++;
			ans++;
		}
	}
	printf("%d\n",ans);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

struct point
{
	int data;
	int index;
};
int a[100010];

bool cmp(int x,int y)
{
	if(x<y)return true;
	else return false;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n,cmp);
	int sum=1;
	for(int i=1;i<n;i++)
	{
		if(a[i]==a[0])sum++;
	}
	printf("%d\n",n-sum);
}


#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <sstream>
#include <string>

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int i = k; i < n; i++)
#define debug printf("Executed ");
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);

#pragma warning(disable : 6031)
#pragma warning(disable : 4101)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);

// Solution

int q, a;

int zeros(int n) {
	int res = 0;

	while (n > 1) {
		res += n % 2 == 0;
		n = n / 2;
	}

	return res;
}

int len(int n) {
	int res = 1;

	while (n > 1) {
		res++;
		n = n / 2;
	}

	return res;
}

int largest_divisor(int n) {
	int smallest = 1;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			smallest = i;
			break;
		}
	}

	if (smallest != 1) return n / smallest;
	else return 1;
}

int main() {
	scanf("%d", &q);

	while (q--) {
		scanf("%d", &a);

		if (zeros(a) != 0) {
			printf("%d\n", (1 << len(a)) - 1);
		} else {
			printf("%d\n", largest_divisor(a));
		}
	}

	return 0;
}


#include <iostream>
using namespace std;

int logb2(int n) {
	int res = 0;
	while (n != 1) { n /= 2; res++; }
	return res;
}

int find_gcd(int &n) {
	int l1 = logb2(n), l2 = logb2(n + 1);
	if (l1 == l2) {	return (1 << (l1 + 1)) - 1; }
	if (l1 % 2) { return n / 3; }
	return 1;
}

int main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int a; cin >> a;
		cout << find_gcd(a) << endl;
	}
	cin.ignore(2); return 0;
}


#include <iostream>
using namespace std;

int logb2(int n) {
	int res = 0;
	while (n != 1) { n /= 2; res++; }
	return res;
}

int find_gcd(int &n) {
	int l1 = logb2(n), l2 = logb2(n + 1);
	if (l1 == l2) {	return (1 << (l1 + 1)) - 1; }
	if (l1 % 2) { return n / 3; }
	int m = (int)floor(sqrt(n + 0.0));
	for (int i = m; i > 1; i--) {
		if (n % i == 0) { return n / i; }
	}
	return 1;
}

int gcd(int a, int b) {
	if (b == 0) { return a; }
	return gcd(b, a % b);
}

int main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int a; cin >> a;
		cout << find_gcd(a) << endl;
	}
	cin.ignore(2); return 0;
}


#include <iostream>
using namespace std;

int logb2(int n) {
	int res = 0;
	while (n != 1) { n /= 2; res++; }
	return res;
}

int find_gcd(int &n) {
	int l1 = logb2(n), l2 = logb2(n + 1);
	if (l1 == l2) {	return (1 << (l1 + 1)) - 1; }
	int m = (int)floor(sqrt(n + 0.0));
	for (int i = 2; i < m; i++) {
		if (n % i == 0) { return n / i; }
	}
	return 1;
}

int gcd(int a, int b) {
	if (b == 0) { return a; }
	return gcd(b, a % b);
}

int main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int a; cin >> a;
		cout << find_gcd(a) << endl;
	}
	cin.ignore(2); return 0;
}


#include <iostream>
using namespace std;

int logb2(int n) {
	int res = 0;
	while (n != 1) { n /= 2; res++; }
	return res;
}

int find_gcd(int &n) {
	int l1 = logb2(n), l2 = logb2(n + 1);
	if (l1 == l2) {	return (1 << (l1 + 1)) - 1; }
	if (l1 % 2) { return n / 3; }
	int m = (int)floor(sqrt(n + 0.0));
	for (int i = 3; i <= m; i++) {
		if (n % i == 0) { return n / i; }
	}
	return 1;
}

int main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int a; cin >> a;
		cout << find_gcd(a) << endl;
	}
	cin.ignore(2); return 0;
}


#include<iostream>
#include<numeric>
#include<math.h>
using namespace std;
int main()
{
	int q;
	cin >> q;
	long a[30] = { 1 };
	long temp = 2;
	for (int i = 1; i <= 25; i++) {
		a[i] = 1;
		a[i] *= temp;
		temp *= 2;
	}

	for (int jjjj = 0; jjjj < q; jjjj++) {
		long num;
		cin >> num;

		int ii = 25;
		while (a[ii] > num) ii--;
		ii++;
		if (a[ii] - 1 != num) cout << a[ii] - 1 << endl;
		else {
			int max = 1;
			int aa = a[ii] - 1;

			for (int i = 2; i * i <= aa; i++) {
				if (!(aa % i)) {
					aa /= i; break;
				}
			}
			if (ii == 2) cout << 1 << endl;
			else {
				if (ii == 3) cout << 1 << endl;
				else{
if (ii == 4) cout << 1 << endl;
else
				cout << aa << endl;
}
			}
		}

	}
}


#include<iostream>
#include<numeric>
#include<math.h>
using namespace std;
int main()
{
	int q;
	cin >> q;
	long a[30] = { 1 };
	long temp = 2;
	for (int i = 1; i <= 25; i++) {
		a[i] = 1;
		a[i] *= temp;
		temp *= 2;
	}

	for (int jjjj = 0; jjjj < q; jjjj++) {
		long num;
		cin >> num;

		int ii = 25;
		while (a[ii] > num) ii--;
		ii++;
		if (a[ii] - 1 != num) cout << a[ii] - 1 << endl;
		else {
			int max = 1;
			int aa = a[ii] - 1;

			for (int i = 2; i * i <= aa; i++) {
				if (!(aa % i)) {
					aa /= i; break;
				}
			}
			if (ii == 2) cout << 1 << endl;
			else {
				if (ii == 3) cou << 1 << endl;
				else
				cout << aa << endl;

			}
		}

	}
}


#include<iostream>
#include<numeric>
using namespace std;
int main()
{
	int q;
	cin >> q;
	long a[30] = { 1 };
	long temp = 2;
	for (int i = 1; i <= 25; i++) {
		a[i] = 1;
		a[i] *= temp;
		temp *= 2;
	}

	for (int jjjj = 0; jjjj < q; jjjj++) {
		long num;
		cin >> num;

		int ii = 25;
		while (a[ii] > num) ii--;
		ii++;
		if (a[ii] - 1 != num) cout << a[ii] - 1 << endl;
		else {
			int max = 1;
			int aa = a[ii] - 1;

			for (int bb = 1; bb <= aa/2; bb++) {
				int temp1 = bb, temp2 = aa;
				temp1 = gcd(temp1, temp2);
				if (temp1 > max) max = temp1;
			}

			cout << max << endl;
		}

	}
}


#include<iostream>
using namespace std;
int main()
{
	int q;
	cin >> q;
	long a[30] = { 1 };
	long temp = 2;
	for (int i = 1; i <= 25; i++) {
		a[i] = 1;
		a[i] *= temp;
		temp *= 2;
	}

	for (int jjjj = 0; jjjj < q; jjjj++) {
		long num;
		cin >> num;

		int ii = 25;
		while (a[ii] > num) ii--;
		ii++;
		if (a[ii] - 1 != num) cout << a[ii] - 1 << endl;
		else {
			int max = 1;
			int aa = a[ii] - 1;

			for (int bb = 1; bb <= aa/2; bb++) {
				int temp1 = bb, temp2 = aa;
				if (temp1 == 1) continue;
				if (temp2 == 1) continue;
				while ((temp1 >= 1) && (temp2 >= 1)) {
					if (temp1 > temp2) temp1 -= temp2;
					if (temp2 > temp1) temp2 -= temp1;
					if (temp1 == temp2) break;
				}
				if (temp1 > max) max = temp1;
				if (temp2 > max) max = temp2;
			}

			cout << max << endl;
		}

	}
}


#include<iostream>
#include<numeric>
#include<math.h>
using namespace std;
int main()
{
	int q;
	cin >> q;
	long a[30] = { 1 };
	long aaaa[26];
	long temp = 2;
	for (int i = 1; i <= 25; i++) {
		a[i] = 1;
		a[i] *= temp;
		temp *= 2;
	}
	aaaa[0] = 0;
	for (int i = 2; i <= 25; i++) {
		int aa = a[i] - 1;
		aaaa[i] = 1;
		for (int j = aa / 2; j > 1; j -= 2) {
			if (!((aa - j) % j)) {aaaa[i]= j; break; }
		}

	}

	for (int jjjj = 0; jjjj < q; jjjj++) {
		long num;
		cin >> num;

		int ii = 25;
		while (a[ii] > num) ii--;
		ii++;
		if (a[ii] - 1 != num) cout << a[ii] - 1 << endl;
		else {
			cout << aaaa[ii] << endl;

		}

	}
}


#include<iostream>
using namespace std;
int main()
{
	int q;
	cin >> q;
	long a[30] = { 1 };
	long temp = 2;
	for (int i = 1; i <= 25; i++) {
		a[i] = 1;
		a[i] *= temp;
		temp *= 2;
	}

	for (int jjjj = 0; jjjj < q; jjjj++) {
		long num;
		cin >> num;

		int ii = 25;
		while (a[ii] > num) ii--;
		ii++;
		if (a[ii] - 1 != num) cout << a[ii] - 1 << endl;
		else {
			int max = 1;
			int aa = a[ii] - 1;

			for (int bb = 1; bb <= aa/2; bb++) {
				int temp1 = bb, temp2 = aa;
				if (temp1 == 1) continue;
				if (temp2 == 1) continue;
				while ((temp1 >= 1) && (temp2 >= 1)) {
					if (temp1 > temp2) temp1 %= temp2;
					else if (temp2 > temp1) temp2 %= temp1;

					{
						if (temp1 == temp2) break;
						if (temp1 == 0) break;
						if (temp2 == 0) break;
					}
				}
				if (temp1 > max) max = temp1;
				if (temp2 > max) max = temp2;
			}

			cout << max << endl;
		}

	}
}


#include<iostream>
using namespace std;
int main()
{
	int q;
	cin >> q;
	long a[30] = { 1 };
	long temp = 2;
	for (int i = 1; i <= 25; i++) {
		a[i] = 1;
		a[i] *= temp;
		temp *= 2;
	}

	for (int jjjj = 0; jjjj < q; jjjj++) {
		long num;
		cin >> num;

		int ii = 25;
		while (a[ii] > num) ii--;
		ii++;
		if (a[ii] - 1 != num) cout << a[ii] - 1 << endl;
		else {
			int max = 1;
			int aa = a[ii] - 1;

			for (int bb = 1; bb*bb <= aa; bb++) {
				int tempmax = 1;
				for (int b = 1; b <= bb; b++) {
					if ((bb % b == 0) && (aa%b == 0)) tempmax = b;
				}
				if (max < tempmax) max = tempmax;
			}

			cout << max << endl;
		}

	}
}


#include<iostream>
using namespace std;
int main()
{
	int q;
	cin >> q;
	long a[30] = { 1 };
	long temp = 2;
	for (int i = 1; i <= 25; i++) {
		a[i] = 1;
		a[i] *= temp;
		temp *= 2;
	}

	for (int jjjj = 0; jjjj < q; jjjj++) {
		long num;
		cin >> num;

		int ii = 25;
		while (a[ii] > num) ii--;
		ii++;
		if (a[ii] - 1 != num) cout << a[ii] - 1 << endl;
		else {
			int max = 1;
			int aa = a[ii] - 1;

			for (int bb = 1; bb <= aa/2; bb++) {
				int tempmax = 1;
				for (int b = 1; b <= bb; b++) {
					if ((bb % b == 0) && (aa%b == 0)) tempmax = b;
				}
				if (max < tempmax) max = tempmax;
			}

			cout << max << endl;
		}

	}
}


#include<iostream>
#include<numeric>
#include<math.h>
using namespace std;
int main()
{
	int q;
	cin >> q;
	long a[30] = { 1 };
	long temp = 2;
	for (int i = 1; i <= 25; i++) {
		a[i] = 1;
		a[i] *= temp;
		temp *= 2;
	}

	for (int jjjj = 0; jjjj < q; jjjj++) {
		long num;
		cin >> num;

		int ii = 25;
		while (a[ii] > num) ii--;
		ii++;
		if (a[ii] - 1 != num) cout << a[ii] - 1 << endl;
		else {
			int max = 1;
			int aa = a[ii] - 1;

			for (int i = aa/2; i >1; i-=2) {
				if (!((aa - i) % i)) {max = i; break; }
			}
			cout << max<<endl;
		}

	}
}


#include<iostream>
#include<numeric>
#include<math.h>
using namespace std;
int main()
{
	int q;
	cin >> q;
	long a[30] = { 1 };
	long temp = 2;
	for (int i = 1; i <= 25; i++) {
		a[i] = 1;
		a[i] *= temp;
		temp *= 2;
	}

	for (int jjjj = 0; jjjj < q; jjjj++) {
		long num;
		cin >> num;

		int ii = 25;
		while (a[ii] > num) ii--;
		ii++;
		if (a[ii] - 1 != num) cout << a[ii] - 1 << endl;
		else {
			int max = 1;
			int aa = a[ii] - 1;

			for (int i = 2; i * i <= aa; i++) {
				if (!(aa % i)) {
					aa /= i; break;
				}
			}

			cout << aa << endl;
		}

	}
}


#include<iostream>
#include<numeric>
#include<math.h>
using namespace std;
int main()
{
	int q;
	cin >> q;
	long a[30] = { 1 };
	long temp = 2;
	for (int i = 1; i <= 25; i++) {
		a[i] = 1;
		a[i] *= temp;
		temp *= 2;
	}

	for (int jjjj = 0; jjjj < q; jjjj++) {
		long num;
		cin >> num;

		int ii = 25;
		while (a[ii] > num) ii--;
		ii++;
		if (a[ii] - 1 != num) cout << a[ii] - 1 << endl;
		else {
			int max = 1;
			int aa = a[ii] - 1;

			for (int i = 2; i * i <= aa; i++) {
				if (!(aa % i)) {
					aa /= i; break;
				}
			}
			if (ii == 2) cout << 1 << endl;
			else {
				if (ii == 3) cout << 1 << endl;
				else
				cout << aa << endl;

			}
		}

	}
}


#include<iostream>
#include<numeric>
#include<math.h>
using namespace std;
int main()
{
	int q;
	cin >> q;
	long a[30] = { 1 };
	long temp = 2;
	for (int i = 1; i <= 25; i++) {
		a[i] = 1;
		a[i] *= temp;
		temp *= 2;
	}

	for (int jjjj = 0; jjjj < q; jjjj++) {
		long num;
		cin >> num;

		int ii = 25;
		while (a[ii] > num) ii--;
		ii++;
		if (a[ii] - 1 != num) cout << a[ii] - 1 << endl;
		else {
			int max = 1;
			int aa = a[ii] - 1;

			for (int i = 2; i <=aa/2; i++) {
				if (!((aa - i) % i)) max = i;
			}
			cout << max<<endl;
		}

	}
}


#include<iostream>
#include<numeric>
#include<math.h>
using namespace std;
int main()
{
	int q;
	cin >> q;
	long a[30] = { 1 };
	long temp = 2;
	for (int i = 1; i <= 25; i++) {
		a[i] = 1;
		a[i] *= temp;
		temp *= 2;
	}

	for (int jjjj = 0; jjjj < q; jjjj++) {
		long num;
		cin >> num;

		int ii = 25;
		while (a[ii] > num) ii--;
		ii++;
		if (a[ii] - 1 != num) cout << a[ii] - 1 << endl;
		else {
			int max = 1;
			int aa = a[ii] - 1;

			for (int i = 2; i * i <= aa; i++) {
				if (!(aa % i)) {
					aa /= i; break;
				}
			}
			if (ii == 2) cout << 1 << endl;
			else {
				cout << aa << endl;

			}
		}

	}
}


#include <iostream>
#include <vector>
#include <stdlib.h>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <cmath>
#include <time.h>
using namespace std;

#define INIT ios::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL)

bool prime_flag[10005];
int prime[3000];
int pTop;

void make_prime()
{
    int i,j;
    for(i=2;i<10005;i++)
    {
        if(!prime_flag[i])
            prime[pTop++] = i;
        for(j=0;j<pTop && i * prime[j] < 10005;j++)
        {
            prime_flag[i * prime[j]] = true;
            if(i % prime[j] == 0)
                break;
        }
    }
}

int main()
{
    INIT;
    make_prime();
    int n;
    cin>>n;
    while(n--)
    {
        int a;
        cin>>a;
        int bitCnt = 0;
        int t = a;
        while(t)
        {
            bitCnt++;
            t >>= 1;
        }
        if(a == ((1<<bitCnt) - 1))
        {
            int ans = 1;
            int i;
            for(i=1;i<pTop && prime[i] < a;i++)
            {
                if(a % prime[i] == 0)
                {
                    ans = a / prime[i];
                    break;
                }
            }
            cout<<ans<<endl;
        }
        else
        {
            cout<<((1<<bitCnt) - 1)<<endl;
        }
    }
}


#include <iostream>
#include <vector>
#include <stdlib.h>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <cmath>
#include <time.h>
using namespace std;

#define INIT ios::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL)

bool prime_flag[10005];
int prime[3000];
int pTop;

void make_prime()
{
    int i,j;
    for(i=2;i<10005;i++)
    {
        if(!prime_flag[i])
            prime[pTop++] = i;
        for(j=0;j<pTop && i * prime[j] < 10005;j++)
        {
            prime_flag[i * prime[j]] = true;
            if(i % prime[j] == 0)
                break;
        }
    }
}

int main()
{
    INIT;
    make_prime();
    int n;
    cin>>n;
    while(n--)
    {
        int a;
        cin>>a;
        int bitCnt = 0;
        int t = a;
        while(t)
        {
            bitCnt++;
            t >>= 1;
        }
        if(a == ((1<<bitCnt) - 1))
        {
            if(a%3)
                cout<<ans/3<<endl;
            else
                cout<<1<<endl;
        }
        else
        {
            cout<<((1<<bitCnt) - 1)<<endl;
        }
    }
}


#include <iostream>
#include <vector>
#include <stdlib.h>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <cmath>
#include <time.h>
using namespace std;

#define INIT ios::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL)

bool prime_flag[10005];
int prime[3000];
int pTop;

void make_prime()
{
    int i,j;
    for(i=2;i<10005;i++)
    {
        if(!prime_flag[i])
            prime[pTop++] = i;
        for(j=0;j<pTop && i * prime[j] < 10005;j++)
        {
            prime_flag[i * prime[j]] = true;
            if(i % prime[j] == 0)
                break;
        }
    }
}

int main()
{
    INIT;
    make_prime();
    int n;
    cin>>n;
    while(n--)
    {
        int a;
        cin>>a;
        int bitCnt = 0;
        int t = a;
        while(t)
        {
            bitCnt++;
            t >>= 1;
        }
        if(a == ((1<<bitCnt) - 1))
        {
            if(a%3 == 0)
                cout<<a/3<<endl;
            else
                cout<<1<<endl;
        }
        else
        {
            cout<<((1<<bitCnt) - 1)<<endl;
        }
    }
}


#include <iostream>
#include <vector>
#include <stdlib.h>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <cmath>
#include <time.h>
using namespace std;

#define INIT ios::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL)

bool prime_flag[10005];
int prime[3000];
int pTop;

void make_prime()
{
    int i,j;
    for(i=2;i<10005;i++)
    {
        if(!prime_flag[i])
            prime[pTop++] = i;
        for(j=0;j<pTop && i * prime[j] < 10005;j++)
        {
            prime_flag[i * prime[j]] = true;
            if(i % prime[j] == 0)
                break;
        }
    }
}

int main()
{
    INIT;
    make_prime();
    int n;
    cin>>n;
    while(n--)
    {
        int a;
        cin>>a;
        int bitCnt = 0;
        int t = a;
        while(t)
        {
            bitCnt++;
            t >>= 1;
        }
        if(a == ((1<<bitCnt) - 1))
        {
            if(a%3)
                cout<<a/3<<endl;
            else
                cout<<1<<endl;
        }
        else
        {
            cout<<((1<<bitCnt) - 1)<<endl;
        }
    }
}


#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <deque>
#include <iostream>
#include <iterator>
#include <locale>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <math.h>
#include <string>
#include <vector>

#define sp << " "
#define sps << " " <<
#define lnl << "\n" <<
#define ln << "\n"
#define vi vector<int>
#define pb push_back
#define pp pop_back
#define forin for(int i = 0; i < n; ++i)
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
typedef long long ll;
using namespace std;

//FUNCTIONS
int nod(ll a, ll b) { while (a != 0 && b != 0)if (a > b)a %= b; else b %= a; return a + b; }//НОД двух чисел
ll nok(ll a, ll b) { return (a * b) / nod(a, b); }//НОК двух чисел
ll binpow(ll a, ll n) { if (n == 0)return 1; if (n % 2 == 1)return binpow(a, n - 1)*a; else return binpow(a*a, n / 2); }//быстрая степень
bool isprime(ll a) { for (int i = 2; i <= sqrt(a); ++i)if (a%i == 0)return false; return true; }//проверка на простое число
const double pi = acos(-1);
const int mod = 1e9 + 7;

//MAIN
int main()
{
#ifdef _DEBUG
	freopen("INPUT.TXT", "rt", stdin);
	freopen("OUTPUT.TXT", "wt", stdout);
#endif
	cout.sync_with_stdio(false);
	cin.sync_with_stdio(false);
	cin.tie(nullptr)->sync_with_stdio(false);

	int b, q;
	cin >> q;
	vector<int> anse = { 1,  1,  5,  1,  21,  1,  85,  73,  341,  89,  1365,  1,  5461,  4681,  21845,  1,  87381,  1,  349525,  299593,  1398101,  178481,  5592405,  1082401 };
	while (q--)
	{
		int a = 0;
		cin >> b;
		for (int i = 26; i >= 0; --i)
		{
			if ((1 << i) < b && !((1 << i)&b))
				a += (1 << i);
		}
		if (a)cout << (a^b) ln;
		else cout << anse[log(b + 1) / log(2) - 2] ln;
	}
}


#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>
using namespace std;
#define lli long long int
const int INF = 987654321;
const int MODV = 1e9 + 7;

int main()
{
	int n, a;
	scanf("%d", &n);
	while (n--) {
		scanf("%d", &a);
		int v = 1;
		while (v <= a) v *= 2;
		if (a == v - 1) printf("1\n");
		else printf("%d\n", v - 1);
	}
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>
using namespace std;
#define lli long long int
const int INF = 987654321;
const int MODV = 1e9 + 7;

int main()
{
	int n, a;
	scanf("%d", &n);
	while (n--) {
		scanf("%d", &a);
		int b = 1;
		int v = 1;
		while (v <= a) {
			v *= 2;
			b++;
		}

		if (a == v - 1) {
			int ans = 1;
			for (int i = 2; i*i <= a; i++) if (a % i == 0) {
				ans = a / i;
				break;
			}
			printf("%d\n", ans);
		}
		else printf("%d\n", v - 1);
	}
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>
using namespace std;
#define lli long long int
const int INF = 987654321;
const int MODV = 1e9 + 7;

int main()
{
	int n, a;
	scanf("%d", &n);
	while (n--) {
		scanf("%d", &a);
		int b = 1;
		int v = 1;
		while (v <= a) {
			v *= 2;
			b++;
		}

		if (a == v - 1) {
			if (b % 2 == 1){
				int ans = 0;
				int tmp = 1;
				for (int i = 1; i < b; i += 2) {
					ans += tmp;
					tmp *= 4;
				}
				printf("%d\n", ans);
			}
			else printf("1\n");
		}
		else printf("%d\n", v - 1);
	}
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>
#include <memory.h>
using namespace std;
#define lli long long int
const int INF = 987654321;
const int MODV = 1e9 + 7;

int gcd(int m, int n) {
	while (n != 0) {
		int t = m % n;
		m = n;
		n = t;
	}
	return m;
}

int dp[34000000];

int func(int a) {
	if (dp[a] != -1) return dp[a];
	int maxv = 0;
	for (int i = 1; i < a; i++)
		maxv = max(maxv, gcd(i ^ a, i & a));
	return dp[a] = maxv;
}
int main()
{
	int n, a;
	scanf("%d", &n);
	memset(dp, -1, sizeof(dp));

	while (n--) {
		scanf("%d", &a);
		int v = 1;
		while (v <= a) v *= 2;
		if (a == v - 1) printf("%d\n", func(a));
		else printf("%d\n", v - 1);
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <string>
using namespace std;
//#define int long long

int main(){
	int q;
	cin >>q;
	while(q--){
		int a;
		cin >> a;
		int q = 0;
		int k =0,l =0;
		while(a>0){
			if (a%2){
				k++;
			}
			else{
				l++;
			}
			a/=2;
			q++;
		}
		if (l!= 0 && k!= 0){
			int ans  = 0;
			for (int i =0;i<q;i++){
				ans+= 1<<i;
			}
			cout << ans;
		}
		else if (l == 0){
			cout << 1;
		}
		cout << '\n';
	}

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <string>
using namespace std;
//#define int long long

int main(){
	int q;
	cin >>q;
	while(q--){
		int a;
		cin >> a;
		int q = 0;
		int k =0,l =0;
		while(a>0){
			if (a%2){
				k++;
			}
			else{
				l++;
			}
			a/=2;
			q++;
		}
		if (l!= 0 && k!= 0){
			int ans  = 0;
			for (int i =0;i<q;i++){
				ans+= 1<<i;
			}
			cout << ans;
		}
		else if (l == 0){
			int ans  = 0;
			for (int i = 0;i<q;i+=2){
				ans +=1<<i;
			}
			cout << ans;
		}
		cout << '\n';
	}

}


#pragma comment(linker, "/STACK:268435456")

//#include "testlib.h"
//#include "problib.h"

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <sstream>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <array>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
typedef unsigned int uint;

#define mp make_pair
#define sqr(a) ((a)*(a))
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define forr(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define forit(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef vector<int> vint;
typedef vector<bool> vbool;
typedef vector<int64> vint64;
typedef vector<uint64> uvint64;
typedef pair<int, int> pii;
typedef pair<int64, int64> pii64;

template<typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p)
{
	in >> p.first >> p.second;
	return in;
}
template<typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p)
{
	out << p.first << " " << p.second;
	return out;
}
template<typename T>
istream& operator >> (istream& in, vector<T>& v)
{
	forn(i, v.size())
	{
		in >> v[i];
	}
	return in;
}
template<typename T>
ostream& operator << (ostream& out, vector<T>& v)
{
	forn(i, v.size())
	{
		out << v[i] << " ";
	}
	return out;
}

int gcd(int a, int b)
{
	return b ? gcd(b, a%b) : a;
}

int main()
{
#ifdef LYZV
	freopen("ReadMe.txt", "r", stdin);
	//freopen("ReadMe.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif

	vint duo(26);
	duo[0] = 1;
	forn(i, 25)
		duo[i + 1] = duo[i] * 2;
	forn(i, 26)
		duo[i]--;
	vint pre= { 0,0,1,1,5,1,21,1,85,73,341,89,1365,1,5461,4681,21845,1,87381,1,349525,299593,1398101,178481,5592405,1082401 };

	int n;
	cin >> n;
	forn(i, n)
	{
		int a;
		cin >> a;
		auto it = lower_bound(duo.begin(), duo.end(), a);
		if (*it == a)
		{
			cout << pre[it - duo.begin()] << endl;
		}
		else
		{
			cout << *it << endl;
		}
	}

	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int MAX_N = 1e5+5;
typedef long long LL;
LL pri[10005],vis[10005],top;
void prime(void)
{
	memset(vis,0,sizeof(vis));
	top = 0;
	for(int i=2; i<10000; i++){
		if(!vis[i]){
			pri[top++] = i;
		for(int j=i*i; j<10000; j+=i) vis[j] = 1;
		}
	}
}
int main(void)
{
	int p;
	prime();
	scanf("%d",&p);
	while(p--)
	{
		LL a,l=2,r=2;
		scanf("%lld",&a);
		for(int i=0; i<25; i++)
		{
			r *= 2;
			if(a>=l&&a<r-1)
			{
				printf("%lld\n",r-1);
				break;
			}
			else if(a == r-1)
			{
				for(int j=0; j<=top; j++)
				{
					if(j!=top&&a>pri[j]&&a%pri[j]==0)
					{
						printf("%lld\n",a/pri[j]);
						break;
					}
					if(j == top) printf("1\n");
				}
				break;
			}
			l *= 2;
		}
	}
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int MAX_N = 1e5+5;
typedef long long LL;
int main(void)
{
	int p;
	scanf("%d",&p);
	while(p--)
	{
		LL a,l=2,r=2;
		scanf("%lld",&a);
		for(int i=0; i<25; i++)
		{
			r *= 2;
			if(a>=l&&a<r-1)
			{
				printf("%lld\n",r-1);
				break;
			}
			else if(a == r-1)
			{
				if(a%3==0) printf("%lld\n",a/3);
				else printf("%lld\n",a);
				break;
			}
			l *= 2;
		}
	}
	return 0;
}


#include <iomanip>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>

#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

const int N = 1000010;
const int MOD = 1e9+7;

const int ans[] = {1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401};

int main() {
    int q;
    cin >> q;
    while (q--) {
        int x;
        cin >> x;
        int b = 0;
        bool f = false;
        while (x) {
            if (x % 2 == 0) f = true;
            b++;
            x /= 2;
        }
        int res;
        if (f) res = (1 << b) - 1;
        else res = ans[b - 2];
        cout << res << endl;
    }
	return 0;
}


#include <iomanip>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>

#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

const int N = 1000010;
const int MOD = 1e9+7;

int main() {
    int q;
    cin >> q;
    while (q--) {
        int x;
        cin >> x;
        int b = 0;
        bool f = false;
        while (x) {
            if (x % 2 == 0) f = true;
            b++;
            x /= 2;
        }
        int res = 0;
        if (f) res = (1 << b) - 1;
        else {
            int y = (1 << b) - 1;
            for (int i = 1; i * i <= y; i++) {
                if (y % i == 0 && i != y) res = max(res, i);
                if (y % i == 0 && y / i != y) res = max(res, y / i);
            }
        }
        cout << res << endl;
    }
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;

bool zhi(int c)
{
    for(int i=2;i<=sqrt(c);i++)
        if(c%i==0) return false;
    return true;
}

int main()
{
int q,r=1;
cin>>q;
set<int>s;
for(int i=0;i<=26;i++)
{
    s.insert(r);
    r=r*2;
}
while(q--)
{
    int w,num=0;
    cin>>w;
    if(!s.count(w+1))
    {
        int t=1;
        for(int i=0;i<=26;i++)
        {
            if(t>w+1) {num=t;break;}
            else t=t*2;
        }
        cout<<num-1;
    }
    else {num=1;
            for(int p=w/3;p>sqrt(w)-1;p--)
            if(w%p==0) {num=p;break;}
            cout<<num;
    }

   if(q!=0) cout<<endl;
}
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;

bool zhi(int c)
{
    for(int i=2;i<=sqrt(c);i++)
        if(c%i==0) return false;
    return true;
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int q,r=1;
cin>>q;
set<int>s;
for(int i=0;i<=26;i++)
{
    s.insert(r);
    r=r*2;
}
while(q--)
{
    int w,num=0;
    cin>>w;
    if(!s.count(w+1))
    {
        int t=1;
        for(int i=0;i<=26;i++)
        {
            if(t>w+1) {num=t;break;}
            else t=t*2;
        }
        cout<<num-1;
    }
    else {num=1;
            for(int p=2;p*p<w;p++)
            if(w%p==0) {num=w/p;break;}
            cout<<num;
    }

 cout<<endl;
}
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;

bool zhi(int c)
{
    for(int i=2;i<=sqrt(c);i++)
        if(c%i==0) return false;
    return true;
}

int main()
{
int q,r=1;
cin>>q;
set<int>s;
for(int i=0;i<=26;i++)
{
    s.insert(r);
    r=r*2;
}
while(q--)
{
    int w,num=0;
    cin>>w;
    if(!s.count(w+1))
    {
        int t=1;
        for(int i=0;i<=26;i++)
        {
            if(t>w+1) {num=t;break;}
            else t=t*2;
        }
        cout<<num-1;
    }
    else {num=1;
            for(int p=w-1;p>sqrt(w)-1;p--)
            if(w%p==0) {num=p;break;}
            cout<<num;
    }

   if(q!=0) cout<<endl;
}
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;

bool zhi(int c)
{
    for(int i=2;i<=sqrt(c);i++)
        if(c%i==0) return false;
    return true;
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int q,r=1;
cin>>q;
set<int>s;
for(int i=0;i<=26;i++)
{
    s.insert(r);
    r=r*2;
}
while(q--)
{
    int w,num=0;
    cin>>w;
    if(!s.count(w+1))
    {
        int t=1;
        for(int i=0;i<=26;i++)
        {
            if(t>w+1) {num=t;break;}
            else t=t*2;
        }
        cout<<num-1;
    }
    else {num=1;
            for(int p=w/3;p>sqrt(w)-1;p--)
            if(w%p==0) {num=p;break;}
            cout<<num;
    }

   if(q!=0) cout<<endl;
}
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;

bool zhi(int c)
{
    for(int i=2;i<=sqrt(c);i++)
        if(c%i==0) return false;
    return true;
}

int main()
{
int q,r=1;
cin>>q;
set<int>s;
for(int i=0;i<=25;i++)
{
    s.insert(r);
    r=r*2;
}
while(q--)
{
    int w,num=0;
    cin>>w;
    if(!s.count(w+1))
    {
        int t=1;
        for(int i=0;i<=25;i++)
        {
            if(t>w+1) {num=t;break;}
            else t=t*2;
        }
        cout<<num-1;
    }
    else {num=1;
            for(int p=w-1;p>1;p--)
                if(w%p==0&&zhi(p)) {num=p;break;}
                cout<<num;
    }

   if(q!=0) cout<<endl;
}
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;

bool zhi(int c)
{
    for(int i=2;i<=sqrt(c);i++)
        if(c%i==0) return false;
    return true;
}

int main()
{

int q,r=1;
cin>>q;
set<int>s;
for(int i=0;i<=26;i++)
{
    s.insert(r);
    r=r*2;
}
while(q--)
{
    int w,num=0;
    cin>>w;
    if(!s.count(w+1))
    {
        int t=1;
        for(int i=0;i<=26;i++)
        {
            if(t>w+1) {num=t;break;}
            else t=t*2;
        }
        cout<<num-1;
    }
    else {num=1;
            for(int p=2;p*p<w;p++)
            if(w%p==0) {num=w/p;break;}
            cout<<num;
    }

 cout<<endl;
}
    return 0;
}


#include<iostream>
#include<stack>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<ctime>
#include<math.h>
#include<functional>
#include<cstring>
#include<iomanip>
#include<set>
#include<utility>
#include<limits.h>
#include<stdio.h>

using namespace std;
int q, n;
int main()
{
	cin >> q;
	for (int i = 0;i < q;i++)
	{
		cin >> n;
		int x = 1;
		int cnt = 1;
		while (x <= n)
		{
			x = pow(2, cnt);
			cnt++;
		}
		x--;
		if (n == x) cout << 1 << endl;
		else cout << x << endl;
	}
	return ~~(0 - 0);
}


#include<iostream>
#include<stack>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<ctime>
#include<math.h>
#include<functional>
#include<cstring>
#include<iomanip>
#include<set>
#include<utility>
#include<limits.h>
#include<stdio.h>

using namespace std;
int q, n;
int main()
{
	cin >> q;
	for (int i = 0;i < q;i++)
	{
		cin >> n;
		int x = 1;
		int cnt = 1;
		while (x <= n)
		{
			x = pow(2, cnt);
			cnt++;
		}
		x--;
		if (n == x)//��Ϊһ�����������������������������������һ�����ı���63���Ե���7*9 ��7���ֳ������������ľ���9
		{
			int maxnum = INT_MIN;
			for (int i = 3;i < sqrt(n);i++)
			{
				if (n%i == 0) maxnum = max(maxnum, n / i);
			}
			if (maxnum == INT_MIN) cout << 1 << endl;
			else cout << maxnum << endl;
		}
		else cout << x << endl;
	}
	return ~~(0 - 0);
}


#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int gcd(int x, int y)
{
	if (x < y) swap(x, y);
	if (y == 0) return x;
	if (x%y == 0) return y;
	return gcd(y, x%y);
}
int a[30];
int max1(int x)
{
	for (int i = 2; i <=(int) sqrt(double(x)); i++)
	{
		if (x%i == 0) return x / i;
	}
	return 1;
}
int main()
{
	int q; cin >> q;
	for (int i = 1; i <= 26; i++) a[i] =(int) pow(2, i) - 1;
	for (int i = 1; i <= q; i++)
	{
		int x; cin >> x;

		int u = 1; while (a[u] < x) ++u;
		if (a[u]!= x) cout << a[u]<< endl;
		else
		{
			cout << max1(x)<<endl;
		}

	}
	//system("pause");
}


#include <iostream>
#include <cmath>

using namespace std;

long long arr[30];

int main()
{
	int n, q;
	cin >> n;
	arr[1] = 2;
	for (int i = 2; i <= 30; i++)
		arr[i] = arr[i - 1] * 2;
	for(int i = 1; i <= 30; i++)
		arr[i]--;
	for (int i = 1; i <= n; i++)
	{
	 	int pos = 1;
		cin >> q;
		for(pos; pos <= 30; pos++)
		{
			if(q < arr[pos])
				break;
		}
		if (arr[pos - 1] == q)
		{
			int flag = 0, x = sqrt(q);
			for (int j = 2; j <= x; j++)
			{
				if (q % j == 0)
				{
					cout << q / j << endl;
					flag = 1;
					break;
				}
			}
			if (!flag)
				cout << 1 << endl;
		}
		else
		{
			cout << arr[pos] << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <map>
#include <string>
#include <set>
using namespace std;

int main()
{
	int q, t;
	cin >> q;
	vector<int> a(q), k(24), e(24, 1); //24 = limit

	for (int i = 0; i < q; i++) {
		cin >> a[i];
	}
	t = 2;
	for (int i = 0; i < 24; i++) {
		t = 2 * t;
		k[i] = t - 1;
	}
	for (int i = 0; i < 24; i++) {
		for (int j = 2; j < k[i]; j++) {
			if (k[i] % j == 0) {
				e[i] = k[i] / j;
				break;
			}
		}
	}

	for (int i = 0; i < q; i++) {
		for (int j = 0; j < 24; j++) {
			if (a[i] == k[j]) {
				cout << e[j] << endl;
				break;
			}
			else if (a[i] < k[j]) {
				cout << k[j] << endl;
				break;
			}
		}
	}

	return 0;
}


#include <iostream>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <map>
#include <string>
#include <set>
using namespace std;

int main()
{
	int q, t;
	cin >> q;
	vector<int> a(q), k(24), e(13);

	for (int i = 0; i < q; i++) {
		cin >> a[i];
	}
	t = 2;
	e[0] = 1;
	for (int i = 0; i < 24; i++) {
		t = 2 * t;
		if (i % 2 == 0) {
			e[i / 2 + 1] = e[i / 2] + t;
		}
		k[i] = t - 1;
	}

	for (int i = 0; i < q; i++) {
		for (int j = 0; j < 24; j++) {
			if (a[i] == k[j]) {
				if (j % 2 == 0) {
					cout << e[j/2] << endl;
				}
				else {
					cout << 1 << endl;
				}
				break;
			}
			else if (a[i] < k[j]) {
				cout << k[j] << endl;
				break;
			}
		}
	}

	return 0;
}


#include <iostream>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <map>
#include <string>
#include <set>
using namespace std;

int main()
{
	int q, t;
	cin >> q;
	vector<int> a(q), k(24);

	for (int i = 0; i < q; i++) {
		cin >> a[i];
	}
	t = 2;
	for (int i = 0; i < 24; i++) {
		t = 2 * t;
		k[i] = t - 1;
	}

	for (int i = 0; i < q; i++) {
		for (int j = 0; j < 24; j++) {
			if (a[i] == k[j]) {
				cout << 1 << endl;
				break;
			}
			else if (a[i] < k[j]) {
				cout << k[j] << endl;
				break;
			}
		}
	}

	return 0;
}