#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int fs[256]={0};
    int rs=0;
    for(int i=0;i<s.length();i++){
        fs[s[i]]++;
    }
    for(int i=0;i<s.length();i++){
        if(fs[s[i]]!=0){
            if(fs[s[i]]>=2){
                rs+=fs[s[i]]-1;
            }
           fs[s[i]]=0;
        }
    }
    cout<<rs<<endl;
    return 0;
}


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

int main()
{
    int n,p=0,flag=0;
    cin>>n;
    char a[n];
    int b[26]={0};
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        a[i]-=97;
       b[(int)a[i]]++;
    }
    if(n>26)
    {
        flag=1;
    }
    else
    {
               for(int i=0;i<26;)
       {

           while(b[i]>1 && b[i]<=26)
           {
               b[i]--;
               p++;
           }

           i++;
       }
    }

    if(flag==1)
        cout<<"-1";
    else
        cout<<p;
	return 0;
}


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

int main()
{
    int n,p=0,flag=0;
    cin>>n;
    char a[n];
    int b[26]={0};
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        a[i]-=97;
       b[(int)a[i]]++;
    }
       for(int i=0;i<26;)
       {
           if(b[i]>26)
           {
               flag=1;
               break;
           }
           while(b[i]>1 && b[i]<=26)
           {
               b[i]--;
               p++;
           }

           i++;
       }
    if(flag==1)
        cout<<"-1";
    else
        cout<<p;
	return 0;
}


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

int main()
{
    int n,p=0;
    cin>>n;
    char a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(a[i]==a[j])
                p++;
        }
    }
    cout<<p;
	return 0;
}


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

int main()
{
    int n,p=0;
    cin>>n;
    char a[n];
    int b[26]={0};
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        a[i]-=97;
       b[(int)a[i]]++;
    }
       for(int i=0;i<26;)
       {
           while(b[i]>1)
           {
               b[i]--;
               p++;
           }
           i++;
       }
    cout<<p;
	return 0;
}


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

int main()
{
    int n,p=0;
    cin>>n;
    char a[n];
    int b[26]={0};
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        a[i]-=97;
       b[(int)a[i]]++;
    }
       for(int i=0;i<26;)
       {
           while(b[i]>1)
           {
               b[i]--;
               p++;
           }
           if(b[i]>26)
           {
               p=-1;
               break;
           }
           i++;
       }
    cout<<p;
	return 0;
}


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

int main()
{
    int n;
    string s;

    cin>>n>>s;

    set<char> s1;
    for(int i=0;i<n;i++)
        s1.insert(s[i]);

    int j=n-s1.size();
    int k=26-s1.size();

    if(j>k)
    cout<<-1<<endl;
    else
    cout<<j<<endl;

    return 0;
}


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

int main()
{
    int n;
    string s;

    cin>>n>>s;

    set<char> s1;
    for(int i=0;i<n;i++)
        s1.insert(s[i]);

    int j=n-s1.size();

    if(j>26)
    cout<<-1<<endl;
    else
    cout<<j<<endl;

    return 0;
}


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

int main()
{
    int n;
    string s;

    cin>>n>>s;

    set<char> s1;
    for(int i=0;i<n;i++)
        s1.insert(s[i]);

    int j=n-s1.size();

    if(j>=26)
    cout<<-1<<endl;
    else
    cout<<j<<endl;

    return 0;
}


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

int main()
{
    int n;
    string s;

    cin>>n>>s;

    set<char> s1;
    for(int i=0;i<n;i++)
        s1.insert(s[i]);

    int j=n-s1.size();

    cout<<j;

    return 0;
}


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

int main()
{
    int n;
    string s;

    cin>>n>>s;

    set<char> s1;
    for(i=0;i<n;i++)
        s1.insert(s[i]);

    int j=n-s1.size();

    cout<<j;

    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include <set>
#include <stdio.h>
using namespace std;
int main()
{
	long n;
	string s;
	set<char>ss;
	cin >> n >> s;
	for (long i = 0; i < n; i++)
	{
		ss.insert(s[i]);
	}int e = ss.size();
	if (abs(n - e) < 26)
		cout << abs(n - e) << endl;
	else
		cout << -1 << endl;
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include <set>
#include <stdio.h>
using namespace std;
int main()
{
	long n;
	string s;
	set<char>ss;
	cin >> n >> s;
	for (long i = 0; i < n; i++)
	{
		ss.insert(s[i]);
	}int e = ss.size();
	if (abs(n - e) <= 26)
		cout << abs(n - e) << endl;
	else
		cout << -1 << endl;
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include <set>
#include <stdio.h>
using namespace std;
int main()
{
	long freq[101] = { 0 }, n, temp, count = 0, e,u=0;
	string s;
	cin >> n >> s;
	for (long i = 0; i < n; i++)
	{
		e = s[i];
		temp = e - 97;
		freq[temp]++;
	}
	for (long i = 0; i < 26; i++)
	{
		if (freq[i] >= 1)u++;
		if (freq[i] > 1)count+=(freq[i]-1);
	}
	if (u + count <= 26)
		cout << count << endl;
	else cout << -1 << endl;
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int freq[1001];
int main()
{
	int c = 0,n;
	string exp;
	cin >> n >> exp;
	for (int i = 0; i < exp.length(); i++)
	{
		if (freq[exp[i] - 97] >= 1)c++;
		else freq[exp[i] - 'a']++;
	}
	int s = sizeof(freq) / sizeof(freq[0]);
	if (n - c <= 26)
	{
		cout << c << endl;
	}
	else cout << -1 << endl;
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include <set>
#include <stdio.h>
using namespace std;
int main()
{
	long n;
	string s;
	set<char>ss;
	cin >> n >> s;
	if (n >=1000) { cout << -1 << endl; return 0; }
	for (long i = 0; i < n; i++)
	{
		ss.insert(s[i]);
	}int e = ss.size();
	if (abs(n - e) > (ceil(n / 2)+1)) { cout << -1 << endl; return 0; }
	cout << abs(n - e) << endl;
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int freq[1001];
int main()
{
	int c = 0;
	string exp;
	cin >> exp;
	for (int i = 0; i < exp.length(); i++)
	{
		if (freq[exp[i] - 97] >= 1)c++;
		else freq[exp[i] - 'a']++;
	}
	int s = sizeof(freq) / sizeof(freq[0]);
	if (c + exp.length() <= 26)
	{
		cout << c << endl;
	}
	else cout << -1 << endl;
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int freq[1001];
int main()
{
	int c = 0,n;
	string exp;
	cin >> n >> exp;
	for (int i = 0; i < exp.length(); i++)
	{
		if (freq[exp[i] - 97] >= 1)c++;
		else freq[exp[i] - 'a']++;
	}
	int s = sizeof(freq) / sizeof(freq[0]);
	if (n  <= 26)
	{
		cout << c << endl;
	}
	else cout << -1 << endl;
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include <set>
#include <stdio.h>
using namespace std;
int main()
{
	long n;
	string s;
	set<char>ss;
	cin >> n >> s;
	if (n >=1000) { cout << -1 << endl; return 0; }
	for (long i = 0; i < n; i++)
	{
		ss.insert(s[i]);
	}int e = ss.size();
	cout << abs(n - e) << endl;
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include <set>
#include <stdio.h>
using namespace std;
int main()
{
	long n;
	string s;
	set<char>ss;
	cin >> n >> s;
	for (long i = 0; i < n; i++)
	{
		ss.insert(s[i]);
	}int e = ss.size();
	if (abs(n - e)+e <= 26)
		cout << abs(n - e) << endl;
	else
		cout << -1 << endl;
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int freq[1001];
int main()
{
	int c = 0,n;
	string exp;
	cin >> n >> exp;
	for (int i = 0; i < exp.length(); i++)
	{
		if (freq[exp[i] - 97] >= 1)c++;
		else freq[exp[i] - 'a']++;
	}
	int s = sizeof(freq) / sizeof(freq[0]);
	if (c + exp.length() <= 26)
	{
		cout << c << endl;
	}
	else cout << -1 << endl;
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include <set>
#include <stdio.h>
using namespace std;
int main()
{
	long n;
	string s;
	set<char>ss;
	cin >> n >> s;
	if (n >=1000) { cout << -1 << endl; return 0; }
	for (long i = 0; i < n; i++)
	{
		ss.insert(s[i]);
	}int e = ss.size();
	if (abs(n - e) > n / 2) { cout << -1 << endl; return 0; }
	cout << abs(n - e) << endl;
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include <set>
#include <stdio.h>
using namespace std;
int main()
{
	long n;
	string s;
	set<char>ss;
	cin >> n >> s;
	for (long i = 0; i < n; i++)
	{
		ss.insert(s[i]);
	}int e = ss.size();
	if (n  <= 26)
		cout << abs(n - e) << endl;
	else
		cout << -1 << endl;
	return 0;
}


/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Jaspreet singh  @jsar3004  Codechef/codeforces/topcoder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
 #include<algorithm>
 #include <iterator>
// #include "boost/algorithm/string.hpp"
#define needforspeed ios_base::sync_with_stdio(false)
#define ll long long int
#define llu unsigned long long int
#define ld long double
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define ff1(i,a,b) for(ll i=a;i<b;i++)
#define ff2(i,b,a) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define pp pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define in insert
#define INTMAX 1000001000
#define ddouble long double
#define PI 3.1415926535
#define coutd(x) cout << fixed << setprecision(x)
#define DECIMAL(n)  std::cout << std::fixed << std::setprecision(n);

using namespace std;
int maxint = numeric_limits<int>::max();
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

void solve()
{
    ll n,co=0,ss=0;
    ll p=0;
    cin>>n;
    string s;
    cin>>s;
    map<int,int>gg;
    ff1(i,0,n)
    {
        gg[s[i]-'a']++;
    }
    ff1(i,0,gg.size())
    {
        if(gg[i]>1)
        {
            co+=gg[i]-1;;
            p++;
        }
        else  if(gg[i]==1)
            ss++;
    }
    if(26-p-ss<0)
    {
        cout<<"-1";
    }
    else
    {
        cout<<co;
    }
    cout<<"\n";
}

int main()
{
    needforspeed;
    ll t=1;
   // cin>>t;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
    while(t--)
    {
       solve();
    }
    return 0;
}


/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Jaspreet singh  @jsar3004  Codechef/codeforces/topcoder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
 #include<algorithm>
 #include <iterator>
// #include "boost/algorithm/string.hpp"
#define needforspeed ios_base::sync_with_stdio(false)
#define ll long long int
#define llu unsigned long long int
#define ld long double
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define ff1(i,a,b) for(ll i=a;i<b;i++)
#define ff2(i,b,a) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define pp pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define in insert
#define INTMAX 1000001000
#define ddouble long double
#define PI 3.1415926535
#define coutd(x) cout << fixed << setprecision(x)
#define DECIMAL(n)  std::cout << std::fixed << std::setprecision(n);

using namespace std;
int maxint = numeric_limits<int>::max();
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

void solve()
{
    ll n,co=0,ss=0;
    ll p=0;
    cin>>n;
    string s;
    cin>>s;
    map<int,int>gg;
    ff1(i,0,n)
    {
        gg[s[i]-'a']++;
    }
    ff1(i,0,gg.size())
    {
        if(gg[i]>1)
        {
            co+=gg[i]-1;;
            p++;
        }
        else  if(gg[i]==1)
            ss++;
    }
    if(26-co-ss<=0)
    {
        cout<<"-1";
    }
    else
    {
        cout<<co;
    }
    cout<<"\n";
}

int main()
{
    needforspeed;
    ll t=1;
   // cin>>t;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
    while(t--)
    {
       solve();
    }
    return 0;
}


/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Jaspreet singh  @jsar3004  Codechef/codeforces/topcoder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
 #include<algorithm>
 #include <iterator>
// #include "boost/algorithm/string.hpp"
#define needforspeed ios_base::sync_with_stdio(false)
#define ll long long int
#define llu unsigned long long int
#define ld long double
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define ff1(i,a,b) for(ll i=a;i<b;i++)
#define ff2(i,b,a) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define pp pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define in insert
#define INTMAX 1000001000
#define ddouble long double
#define PI 3.1415926535
#define coutd(x) cout << fixed << setprecision(x)
#define DECIMAL(n)  std::cout << std::fixed << std::setprecision(n);

using namespace std;
int maxint = numeric_limits<int>::max();
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

void solve()
{
    ll n,co=0,ss=0;
    ll p=0;
    cin>>n;
    string s;
    cin>>s;
    map<int,int>gg;
    ff1(i,0,n)
    {
        gg[s[i]-'a']++;
    }
    ff1(i,0,gg.size())
    {
        if(gg[i]>1)
        {
            co+=gg[i]-1;;
            p++;
        }
        else  if(gg[i]==1)
            ss++;
    }
    if(n>26)
    {
        cout<<"-1";
    }
    else
    {
        cout<<co;
    }
    cout<<"\n";
}

int main()
{
    needforspeed;
    ll t=1;
   // cin>>t;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
    while(t--)
    {
       solve();
    }
    return 0;
}


/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Jaspreet singh  @jsar3004  Codechef/codeforces/topcoder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
 #include<algorithm>
 #include <iterator>
// #include "boost/algorithm/string.hpp"
#define needforspeed ios_base::sync_with_stdio(false)
#define ll long long int
#define llu unsigned long long int
#define ld long double
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define ff1(i,a,b) for(ll i=a;i<b;i++)
#define ff2(i,b,a) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define pp pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define in insert
#define INTMAX 1000001000
#define ddouble long double
#define PI 3.1415926535
#define coutd(x) cout << fixed << setprecision(x)
#define DECIMAL(n)  std::cout << std::fixed << std::setprecision(n);

using namespace std;
int maxint = numeric_limits<int>::max();
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

void solve()
{
    ll n,co=0,ss=0;
    ll p=0;
    cin>>n;
    string s;
    cin>>s;
    map<int,int>gg;
    ff1(i,0,n)
    {
        gg[s[i]-'a']++;
    }
    ff1(i,0,gg.size())
    {
        if(gg[i]>1)
        {
            co+=gg[i]-1;;
            p++;
        }
        else  if(gg[i]==1)
            ss++;
    }
    if(26-co-ss<0)
    {
        cout<<"-1";
    }
    else
    {
        cout<<co;
    }
    cout<<"\n";
}

int main()
{
    needforspeed;
    ll t=1;
   // cin>>t;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
    while(t--)
    {
       solve();
    }
    return 0;
}


/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Jaspreet singh  @jsar3004  Codechef/codeforces/topcoder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
 #include<algorithm>
 #include <iterator>
// #include "boost/algorithm/string.hpp"
#define needforspeed ios_base::sync_with_stdio(false)
#define ll long long int
#define llu unsigned long long int
#define ld long double
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define ff1(i,a,b) for(ll i=a;i<b;i++)
#define ff2(i,b,a) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define pp pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define in insert
#define INTMAX 1000001000
#define ddouble long double
#define PI 3.1415926535
#define coutd(x) cout << fixed << setprecision(x)
#define DECIMAL(n)  std::cout << std::fixed << std::setprecision(n);

using namespace std;
int maxint = numeric_limits<int>::max();
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

void solve()
{
    ll n,co=0,ss=0;
    ll p=0;
    cin>>n;
    string s;
    cin>>s;
    map<int,int>gg;
    ff1(i,0,n)
    {
        gg[s[i]-'a']++;
    }
    ff1(i,0,gg.size())
    {
        if(gg[i]>1)
        {
            co+=gg[i]-1;;
            p++;
        }
        else  if(gg[i]==1)
            ss++;
    }
    if(27-co-ss<0)
    {
        cout<<"-1";
    }
    else
    {
        cout<<co;
    }
    cout<<"\n";
}

int main()
{
    needforspeed;
    ll t=1;
   // cin>>t;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
    while(t--)
    {
       solve();
    }
    return 0;
}


/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Jaspreet singh  @jsar3004  Codechef/codeforces/topcoder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
 #include<algorithm>
 #include <iterator>
// #include "boost/algorithm/string.hpp"
#define needforspeed ios_base::sync_with_stdio(false)
#define ll long long int
#define llu unsigned long long int
#define ld long double
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define ff1(i,a,b) for(ll i=a;i<b;i++)
#define ff2(i,b,a) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define pp pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define in insert
#define INTMAX 1000001000
#define ddouble long double
#define PI 3.1415926535
#define coutd(x) cout << fixed << setprecision(x)
#define DECIMAL(n)  std::cout << std::fixed << std::setprecision(n);

using namespace std;
int maxint = numeric_limits<int>::max();
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

void solve()
{
    ll n,co=0,ss=0;
    cin>>n;
    string s;
    cin>>s;
    map<int,int>gg;
    ff1(i,0,n)
    {
        gg[s[i]-'a']++;
    }
    ff1(i,0,gg.size())
    {
        if(gg[i]>1)
        {
            co++;
        }
        else  if(gg[i]==1)
            ss++;
    }
    if(26-co-ss<0)
    {
        cout<<"-1";
    }
    else
    {
        cout<<co;
    }
    cout<<"\n";
}

int main()
{
    needforspeed;
    ll t=1;
   // cin>>t;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
    while(t--)
    {
       solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

int n, m;
string s;
char c[N];

int main(){
	cin>>n>>s;
	for(int i=0; i<=s.size(); i++)
		c[s[i]]++;

	int ans=0;
	for(int i='a'; i<='z'; i ++)
		if(c[i]>1)
			ans+=c[i]-1;
	cout<<ans;
}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

int n, m;
string s;
int c[N];
int ans, x;

int main(){
	cin>>n>>s;
	for(int i=0; i<s.size(); i++)
		c[s[i]]++;

	for(int i='a'; i<='z'; i ++){
		if(c[i]>1)
			ans+=c[i]-1;
		if(c[i]==0)
			x++;
	}
	if(x < ans)
		cout<<-1;
	else cout<<ans;
}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

int n, m;
string s;
char c[N];

int main(){
	cin>>n>>s;
	for(int i=0; i<=s.size(); i++)
		c[s[i]]++;

	int ans=0, x;
	for(int i='a'; i<='z'; i ++){
		if(c[i]>1)
			ans+=c[i]-1;
		if(c[i]==0)
			x++;
	}
	if(x<ans)
		cout<<-1;
	else
		cout<<ans;
}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

int n, m;
string s;
char c[N];

int main(){
	cin>>n>>s;
	for(int i=0; i<=s.size(); i++)
		c[s[i]]++;

	int ans=0;
	for(int i='a'; i<='z'; i ++)
		if(c[i]>1)
			ans++;
	cout<<ans;
}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

int n, m;
string s;
char c[N];

int main(){
	cin>>n>>s;
	for(int i=0; i<=s.size(); i++)
		c[s[i]]++;

	int ans=0, x=0;
	for(int i='a'; i<='z'; i ++){
		if(c[i]>1)
			ans+=c[i]-1;
		if(c[i]==0)
			x++;
	}
	if(x < ans)
		cout<<-1;
	else
		cout<<ans;
}


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

int main() {

	int n,c=0,count =0;
	cin>>n;

	string s;
	cin>>s;
	unordered_map <char,int> m;

	for(int i=0;i<n;i++)
    {
        m[s[i]]++;
    }

    c = m.size();

    for(auto x:m)
    {
        if(x.second >= 2)
            count += (x.second - 1);

        if(count > (26 - c)){
            count = -1;
            break;
        }
    }

    cout<<count;

	return 0;
}


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

int main() {

	int n,c=0;
	cin>>n;

	string s;
	cin>>s;
	unordered_map <char,int> m;

	for(int i=0;i<n;i++)
    {
        m[s[i]]++;
    }

    for(auto x:m)
    {
        if(x.second>=2)
            c += (x.second -1);
    }

    cout<<c;

	return 0;
}


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

int main() {

	int n,c=0;
	cin>>n;

	string s;
	cin>>s;
	unordered_map <char,int> m;

	for(int i=0;i<n;i++)
    {
        m[s[i]]++;
    }

    for(auto x:m)
    {
        if(x.second>=2)
            c += (x.second -1);

        if(c>26){
            c = -1;
            break;
        }
    }

    cout<<c;

	return 0;
}


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

int main() {

	int n,c=0,count =0;
	cin>>n;

	string s;
	cin>>s;
	unordered_map <char,int> m;

	for(int i=0;i<n;i++)
    {
        m[s[i]]++;
    }

    c = m.size();
    cout<<c<<" ";

    for(auto x:m)
    {
        if(x.second >= 2)
            count += (x.second - 1);

        cout<<count<<" ";

        if(count > (26 - c)){
            count = -1;
            break;
        }
    }

    cout<<count;

	return 0;
}


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

int main() {

	int n,c=0;
	cin>>n;

	string s;
	cin>>s;
	unordered_map <char,int> m;

	for(int i=0;i<n;i++)
    {
        m[s[i]]++;
    }

    for(auto x:m)
    {
        if(x.second>=2)
            c++;
    }

    cout<<c;

	return 0;
}


#include <bits/stdc++.h>//solved by *ALIKHAN*
#define ll long long
#define ld long double
#define str string
#define pb push_back
#define sz() size()
#define ppb pop_back
#define mp make_pair
#define all(n) n.begin(), n.end()
#define timefaster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//////////////
//const ll N=1e9+5;//const
//const ll T=1e6+123;//const

//set <int> st;//set
//map <string,int> mpstr; //multiset

ll a[101010];
// ll doua[666][666];//masiv
// char q,ch[101010];//char
ll l,r,pref[101010];//prefix sum
////////
ll ans,cnt,sum,max1,min1,ali;//intigers
///////////////
int main(){
	timefaster;
	ll n;
	str s;
	cin>>n;
	cin >> s;
	if(s.sz() >= 27) {
		cout << -1;
		return 0;
	}
	for(ll i = 0;i < n; i++){
		if(a[s[i] - '0'] >= 1) ans ++;
		else a[s[i] - '0'] ++;
	}
	if ( ans >= 26) {
		cout<< -1;
		return 0;
	}
	cout << ans;

}
// Aksay sila


#include <bits/stdc++.h>//solved by *ALIKHAN*
#define ll long long
#define ld long double
#define str string
#define pb push_back
#define sz() size()
#define ppb pop_back
#define mp make_pair
#define all(n) n.begin(), n.end()
#define timefaster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//////////////
//const ll N=1e9+5;//const
//const ll T=1e6+123;//const

//set <int> st;//set
//map <string,int> mpstr; //multiset

ll a[101010];
// ll doua[666][666];//masiv
// char q,ch[101010];//char
ll l,r,pref[101010];//prefix sum
////////
ll ans,cnt,sum,max1,min1,ali;//intigers
///////////////
int main(){
	timefaster;
	ll n;
	str s;
	cin>>n;
	cin >> s;
	for(ll i = 0;i < n; i++){
		if(a[s[i] - '0'] >= 1) ans ++;
		else a[s[i] - '0'] ++;
	}
	if ( ans >= 26) {
		cout<< -1;
		return 0;
	}
	cout << ans;

}
// Aksay sila


#include <bits/stdc++.h>//solved by *ALIKHAN*
#define ll long long
#define ld long double
#define str string
#define pb push_back
#define sz() size()
#define ppb pop_back
#define mp make_pair
#define all(n) n.begin(), n.end()
#define timefaster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//////////////
//const ll N=1e9+5;//const
//const ll T=1e6+123;//const

//set <int> st;//set
//map <string,int> mpstr; //multiset

ll a[101010];
// ll doua[666][666];//masiv
// char q,ch[101010];//char
ll l,r,pref[101010];//prefix sum
////////
ll ans,cnt,sum,max1,min1,ali;//intigers
///////////////
int main(){
	timefaster;
	ll n;
	str s;
	cin>>n;
	cin >> s;
	for(ll i = 0;i < n; i++){
		if(a[s[i] - '0'] >= 1) ans ++;
		else a[s[i] - '0'] ++;
	}
	if ( ans > 26) {
		cout<< -1;
		return 0;
	}
	cout << ans;

}
// Aksay sila


#include <bits/stdc++.h>//solved by *ALIKHAN*
#define ll long long
#define ld long double
#define str string
#define pb push_back
#define sz() size()
#define ppb pop_back
#define mp make_pair
#define all(n) n.begin(), n.end()
#define timefaster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//////////////
//const ll N=1e9+5;//const
//const ll T=1e6+123;//const

//set <int> st;//set
//map <string,int> mpstr; //multiset

ll a[101010];
// ll doua[666][666];//masiv
// char q,ch[101010];//char
ll l,r,pref[101010];//prefix sum
////////
ll ans,cnt,sum,max1,min1,ali;//intigers
///////////////
int main(){
	timefaster;
	ll n;
	str s;
	cin>>n;
	cin >> s;
	for(ll i = 0;i < n; i++){
		if(a[s[i] - '0'] >= 1) ans ++;
		else a[s[i] - '0'] ++;
	}
	if ( ans >= 26 + 2) {
		cout<< -1;
		return 0;
	}
	cout << ans;

}
// Aksay sila


#include <bits/stdc++.h>//solved by *ALIKHAN*
#define ll long long
#define ld long double
#define str string
#define pb push_back
#define sz() size()
#define ppb pop_back
#define mp make_pair
#define all(n) n.begin(), n.end()
#define timefaster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//////////////
//const ll N=1e9+5;//const
//const ll T=1e6+123;//const

//set <int> st;//set
//map <string,int> mpstr; //multiset

ll a[101010];
// ll doua[666][666];//masiv
// char q,ch[101010];//char
ll l,r,pref[101010];//prefix sum
////////
ll ans,cnt,sum,max1,min1,ali;//intigers
///////////////
int main(){
	timefaster;
	ll n;
	str s;
	cin>>n;
	cin >> s;
	for(ll i = 0;i < n; i++){
		if(a[s[i] - '0'] >= 1) ans ++;
		else a[s[i] - '0'] ++;
	}
	cout << ans;

}
// Aksay sila


#include <bits/stdc++.h>
using namespace std;
set<char> st;
int main(){
int n;
string s;
cin>>n;
cin>>s;
for(int i=0;i<n;i++){
  st.insert(s[i]);
}
if(n>26){
    cout<<-1;
    return 0;
}
cout<<n-st.size();

   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int n,x=0,w[26]={0};
string s;
cin>>n;
cin>>s;
for(int i=0;i<n;i++){
  w[s[i]-'a']++;
}
for(int i=0;i<26;i++){
    if(w[i]>1)x+=(w[i]-1);
}
if(x>25){
    cout<<-1;
    return 0;
}
cout<<x;

   return 0;
}


#include <bits/stdc++.h>
using namespace std;
set<char> st;
int main(){
int n;
string s;
cin>>n;
cin>>s;
if(n>26){
    cout<<-1;
    return 0;
}
for(int i=0;i<n;i++){
  st.insert(s[i]);
}
cout<<n-st.size();

   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int n,x=0,w[26]={0};
string s;
cin>>n;
cin>>s;
for(int i=0;i<n;i++){
  w[s[i]-'a']++;
}
for(int i=0;i<26;i++){
    if(w[i]>1)x+=(w[i]-1);
}
cout<<x;

   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int n,x=0,w[26]={0};
string s;
cin>>n;
cin>>s;
for(int i=0;i<n;i++){
  w[s[i]-'a']++;
}
for(int i=0;i<26;i++){
    if(w[i]>1)x+=(w[i]-1);
}
if(x>26){
    cout<<-1;
    return 0;
}
cout<<x;

   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int n,x=0,w[26]={0};
string s;
cin>>n;
cin>>s;
for(int i=0;i<n;i++){
  w[s[i]-'a']++;
}
for(int i=0;i<26;i++){
    if(w[i]>1)x+=(w[i]-1);
}
if(n>26){
    cout<<-1;
    return 0;
}
cout<<x;

   return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int n,x=0,w[26]={0};
string s;
cin>>n;
cin>>s;
for(int i=0;i<n;i++){
  w[s[i]-'a']++;
}
for(int i=0;i<26;i++){
    if(w[i]>1)x++;
}
cout<<x;

   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
const double EPS =(1e-7);
int dcmp(double x,double y)
{
    return fabs(x-y)<= EPS ? 0 : x < y ? -1 : 1;
}
const int N=2e5+5;
int main()
{
    quick
int n,ans=0; cin>>n;string s; cin>>s; map<char,int>mp;
for(auto i:s){mp[i]++;}
for(auto i:mp){if(i.second>1){ans+=i.second-1;}}
if(ans>26){cout<<-1;}
else{cout<<ans;}
return 0;
}


#include "bits/stdc++.h"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
set<char>st;
int main() {
quick
int n; string s; cin>>n>>s;
for(auto i:s){st.insert(i);}
cout<<n-st.size();
}


#include<bits/stdc++.h>
using namespace std;
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
const double EPS =(1e-7);
int dcmp(double x,double y)
{
    return fabs(x-y)<= EPS ? 0 : x < y ? -1 : 1;
}
const int N=2e5+5;
int main()
{
    quick
int n,ans=0; cin>>n;string s; cin>>s; map<char,int>mp;
for(auto i:s){mp[i]++;}
for(auto i:mp){if(i.second>1){ans++;}}
cout<<ans;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
const double EPS =(1e-7);
int dcmp(double x,double y)
{
    return fabs(x-y)<= EPS ? 0 : x < y ? -1 : 1;
}
const int N=2e5+5;
int main()
{
    quick
int n,ans=0; cin>>n;string s; cin>>s; map<char,int>mp;
for(auto i:s){mp[i]++;}
for(auto i:mp){if(i.second>1){ans+=i.second-1;}}
cout<<ans;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
quick
int n,sum=0; string s; cin>>n>>s; map<char,int>mp;
for(int i=0;i<n;i++){mp[s[i]]++;}
for(auto i:mp){sum+=i.second/2;}
cout<<sum;
return 0;
}


#include "bits/stdc++.h"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
set<char>st;
int main() {
quick
int n; string s; cin>>n>>s;
for(auto i:s){st.insert(i);}
if((26-st.size())<n-st.size()){cout<<-1;}
else{cout<<n-st.size();}
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
quick
int n,sum=0; string s; cin>>n>>s; map<char,int>mp;
for(int i=0;i<n;i++){mp[s[i]]++;}
for(auto i:mp){if(i.second%2&&i.second!=1){sum+=i.second/2+1;}    else{sum+=i.second/2;}}
cout<<sum;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
const double EPS =(1e-7);
int dcmp(double x,double y)
{
    return fabs(x-y)<= EPS ? 0 : x < y ? -1 : 1;
}
const int N=2e5+5;
int main()
{
    quick
int n,ans=0; cin>>n;string s; cin>>s; map<char,int>mp;
for(auto i:s){mp[i]++;}
for(auto i:mp){if(i.second>1){ans+=i.second-1;}}
if(ans>25){cout<<-1;}
else{cout<<ans;}
return 0;
}


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

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   string x;
   int sum=0,ok=0;
   int n;
   cin>>n;
   cin>>x;
   int arr[30];
   for(int i=0;i<30;i++){
    arr[i]=0;
   }
   for(unsigned int i=0;i<x.size();i++)
   {
       int val=x[i]-97;
       arr[val]=arr[val]+1;
   }
   for(int i=0;i<=26;i++){
    if(arr[i]!=0){
        sum=sum + arr[i]-1;
    }
    if(arr[i]>=1){
        ok++;
    }
   }
   if(sum-ok>=26){
    cout<<-1;
   }else{
   cout<<sum;
   }

}


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

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   string x;
   int sum=0;
   int n;
   cin>>n;
   cin>>x;
   int arr[30];
   for(int i=0;i<=30;i++){
    arr[i]=0;
   }
   for(unsigned int i=0;i<x.size();i++)
   {
       int val=x[i]-97;
       arr[val]=arr[val]+1;
   }
   for(int i=0;i<=26;i++){
    if(arr[i]!=0){
        sum=sum + arr[i]-1;
    }
   }
   cout<<sum;
}


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

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   string x;
   int sum=0,ok=0;
   int n;
   cin>>n;
   cin>>x;
   int arr[30];
   for(int i=0;i<30;i++){
    arr[i]=0;
   }
   for(unsigned int i=0;i<x.size();i++)
   {
       int val=x[i]-97;
       arr[val]=arr[val]+1;
   }
   for(int i=0;i<26;i++){
    if(arr[i]!=0){
        sum=sum + arr[i]-1;
    }
    if(arr[i]>=1){
        ok++;
    }
   }
   if(sum>(26-ok)){
    cout<<-1;
   }else{
   cout<<sum;
   }

}


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

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   string x;
   int sum=0;
   int n;
   cin>>n;
   cin>>x;
   int arr[30];
   for(int i=0;i<=30;i++){
    arr[i]=0;
   }
   for(unsigned int i=0;i<x.size();i++)
   {
       int val=x[i]-97;
       arr[val]=arr[val]+1;
   }
   for(int i=0;i<=26;i++){
    if(arr[i]!=0){
        sum=sum + arr[i]-1;
    }
   }
   if(sum!=0)
   cout<<sum;
   else
    cout<<-1;
}


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

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   string x;
   int sum=0,ok=0;
   int n;
   cin>>n;
   cin>>x;
   int arr[30];
   for(int i=0;i<30;i++){
    arr[i]=0;
   }
   for(unsigned int i=0;i<x.size();i++)
   {
       int val=x[i]-97;
       arr[val]=arr[val]+1;
   }
   for(int i=0;i<=26;i++){
    if(arr[i]!=0){
        sum=sum + arr[i]-1;
    }
    if(arr[i]>=1){
        ok++;
    }
   }
   if(sum-ok>26){
    cout<<-1;
   }else{
   cout<<sum;
   }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
set<char>s1;
for(int i=0;i<n;i++)
s1.insert(s[i]);
if(n>26)
cout<<"-1";
else if(s1.size()<n&&n-s1.size()<26)
cout<<n-s1.size();
else
cout<<"0";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
set<char>s1;
for(int i=0;i<n;i++)
s1.insert(s[i]);
if(s1.size()<n)
cout<<n-s1.size();
else if(n-s1.size()>26)
cout<<"-1";
else
cout<<"0";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
set<char>s1;
for(int i=0;i<n;i++)
s1.insert(s[i]);
if(s1.size()<n&&n-s1.size()<26)
cout<<n-s1.size();
else if(n-s1.size()>26)
cout<<"-1";
else
cout<<"0";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
set<char>s1;
for(int i=0;i<n;i++)
s1.insert(s[i]);
if(n>26)
cout<<"-1";
if(s1.size()<n&&n-s1.size()<26)
cout<<n-s1.size();
else
cout<<"0";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
set<char>s1;
for(int i=0;i<n;i++)
s1.insert(s[i]);
if(s1.size()<n&&n-s1.size()<26)
cout<<n-s1.size();
else if(n-s1.size()>=26)
cout<<"-1";
else
cout<<"0";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
set<char>s1;
for(int i=0;i<n;i++)
s1.insert(s[i]);
if(s1.size()<n)
cout<<n-s1.size();
else
cout<<"0";
return 0;
}


//672B
#include <bits/stdc++.h>
using namespace std;
#define ll long long ;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define V v.push_back ();
#define F first;
#define S second;
#define I(a) insert(a);
#define M_H_L return 0;
int x,n;
set <char> a;
string s;
int main()
{
  cin>>n;
  cin>>s;
  for(int i=0 ; i< n ; i++ )
  {
    if(a.find(s[i])==a.end()){
    a.I(s[i]);
    }
    else
    ++x;
  }
  if(x>=26)
  cout<<-1;
  else
  cout<<x;

  M_H_L
}


//672B
#include <bits/stdc++.h>
using namespace std;
#define ll long long ;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define V v.push_back ();
#define F first;
#define S second;
#define I(a) insert(a);
#define M_H_L return 0;
int x,n;
set <char> a;
string s;
int main()
{
  cin>>n;
  cin>>s;
  for(int i=0 ; i< n ; i++ )
  {
    if(a.find(s[i])==a.end()){
    a.I(s[i]);
    }
    else
    ++x;
  }
  if(x>26)
  cout<<-1;
  else
  cout<<x;

  M_H_L
}


//627B
#include <bits/stdc++.h>
using namespace std;
#define ll long long ;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define V v.push_back ();
#define F first;
#define S second;
#define I(a) insert(a);
#define M_H_L return 0;
int x,n;
set <char> a;
string s;
int main()
{
  cin>>n;
  cin>>s;
  for(int i=0 ; i< n ; i++ )
  {
    if(a.find(s[i])==a.end()){
    a.I(s[i]);
    }
    else
    ++x;
  }

  cout<<x;
}


//672B
#include <bits/stdc++.h>
using namespace std;
#define ll long long ;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define V v.push_back ();
#define F first;
#define S second;
#define I(a) insert(a);
#define M_H_L return 0;
int x,n;
set <char> a;
string s;
int main()
{
  cin>>n;
  cin>>s;
  for(int i=0 ; i< n ; i++ )
  {
    a.I(s[i]);

  }
  if(a.size()>=26)
  cout<<-1;
  else
  cout<<n-a.size();

  M_H_L
}


//672B
#include <bits/stdc++.h>
using namespace std;
#define ll long long ;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define V v.push_back ();
#define F first;
#define S second;
#define I(a) insert(a);
#define M_H_L return 0;
int x,n;
set <char> a;
string s;
int main()
{
  cin>>n;
  cin>>s;
  for(int i=0 ; i< n ; i++ )
  {
    if(a.find(s[i])==a.end()){
    a.I(s[i]);
    }
    else
    ++x;
  }
  if(x>=26)
  cout<<-1;
  else
  cout<<n-x;

  M_H_L
}


//672B
#include <bits/stdc++.h>
using namespace std;
#define ll long long ;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define V v.push_back ();
#define F first;
#define S second;
#define I(a) insert(a);
#define M_H_L return 0;
int x,n,c;
set <char> a;
string s;
int main()
{
  cin>>n;
  cin>>s;

  for(int i=0 ; i< n ; i++ )
  {

    if(a.find(s[i])==a.end()){
    a.I(s[i]);
    }
    else
    ++x;
  }
  c=26-a.size();
  if(x>c)
  cout<<-1;
  else
  cout<<x;

         M_H_L
}


//672B
#include <bits/stdc++.h>
using namespace std;
#define ll long long ;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define V v.push_back ();
#define F first;
#define S second;
#define I(a) insert(a);
#define M_H_L return 0;
int x,n;
set <char> a;
string s;
int main()
{
  cin>>n;
  cin>>s;
  for(int i=0 ; i< n ; i++ )
  {
    a.I(s[i]);

  }
  if(x>=26)
  cout<<-1;
  else
  cout<<n-a.size();

  M_H_L
}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#ifndef ONLINE_JUDGE
    #include <lol.h>
#endif

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007

bool dp[(1<<22)],has[(1<<22)];
int ans[(1<<22)];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("/home/srinivas/Desktop/cp/input.txt","r",stdin);
        //freopen("/home/srinivas/Desktop/output.txt","w",stdout);
    #endif
    int n;
    cin>>n;
    int a[n];
    ifr(i,0,n) cin>>a[i],has[a[i]]=1;
    ifr(i,0,(1<<22)){
        dp[i]=has[i];
        if(dp[i]) ans[i]=i;
    }
    ifr(i,0,22) {
        ifr(mask,0,(1<<22)){
            if(mask & (1<<i)){
                if(dp[mask^(1<<i)]) ans[mask]=ans[mask^(1<<i)];
                dp[mask]|=dp[mask^(1<<i)];
            }
        }
    }
    ifr(i,0,n) {
        // dbgm((a[i] ^ ( (1<<22) -1 )))
        // dbg(dp[(a[i] ^ ( (1<<22) -1 ))])
        // dbg(ans[(a[i] ^ ( (1<<22) -1 ))])
        if(dp[(a[i] ^ ( (1<<22) -1 ) )])
            cout<<ans[(a[i] ^ ( (1<<22) -1 ) )]<<" ";
        else
            cout<<"-1 ";
    }
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#ifndef ONLINE_JUDGE
    #include <lol.h>
#endif

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007

bool dp[(1<<22)][23],has[(1<<22)];
int ans[(1<<22)][23];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("/home/srinivas/Desktop/cp/input.txt","r",stdin);
        //freopen("/home/srinivas/Desktop/output.txt","w",stdout);
    #endif
    int n;
    cin>>n;
    int a[n];
    ifr(i,0,n) cin>>a[i],has[a[i]]=1;
    ifr(mask,0,(1<<22)) {
        dp[mask][0]=has[mask];
        if(has[mask]) ans[mask][0]=mask;
        ifr(i,1,23) {
            if(mask&(1<<(i-1))) {
                if(dp[mask][i-1]) ans[mask][i] = ans[mask][i-1];
                if(dp[mask^(1<<(i-1))][i-1]) ans[mask][i] = ans[mask^(1<<(i-1))][i-1];
                dp[mask][i] = dp[mask][i-1] | dp[mask^(1<<(i-1))][i-1];
            }
            else{
                if(dp[mask][i-1]) ans[mask][i] = ans[mask][i-1];
                dp[mask][i] = dp[mask][i-1];
            }
        }
    }
    ifr(i,0,n) {
        // dbgm((a[i] ^ ( (1<<22) -1 )))
        // dbg(dp[(a[i] ^ ( (1<<22) -1 ))])
        // dbg(ans[(a[i] ^ ( (1<<22) -1 ))])
        if(dp[(a[i] ^ ( (1<<22) -1 ) )][22])
            cout<<ans[(a[i] ^ ( (1<<22) -1 ) )][22]<<" ";
        else
            cout<<"-1 ";
    }
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#ifndef ONLINE_JUDGE
    #include <lol.h>
#endif

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007

bool dp[(1<<22)][23];
int ans[(1<<22)][23];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("/home/srinivas/Desktop/cp/input.txt","r",stdin);
        //freopen("/home/srinivas/Desktop/output.txt","w",stdout);
    #endif
    int n;
    cin>>n;
    int a[n];
    set<int> s;
    ifr(i,0,n) cin>>a[i],s.insert(a[i]);
    ifr(mask,0,(1<<22)) {
        dp[mask][0]=(s.find(mask)!=s.end());
        if(dp[mask][0]) ans[mask][0]=mask;
        ifr(i,1,23) {
            if(mask&(1<<(i-1))) {
                if(dp[mask][i-1]) ans[mask][i] = ans[mask][i-1];
                if(dp[mask^(1<<(i-1))][i-1]) ans[mask][i] = ans[mask^(1<<(i-1))][i-1];
                dp[mask][i] = dp[mask][i-1] | dp[mask^(1<<(i-1))][i-1];
            }
            else{
                if(dp[mask][i-1]) ans[mask][i] = ans[mask][i-1];
                dp[mask][i] = dp[mask][i-1];
            }
        }
    }
    ifr(i,0,n) {
        // dbgm((a[i] ^ ( (1<<22) -1 )))
        // dbg(dp[(a[i] ^ ( (1<<22) -1 ))])
        // dbg(ans[(a[i] ^ ( (1<<22) -1 ))])
        if(dp[(a[i] ^ ( (1<<22) -1 ) )][22])
            cout<<ans[(a[i] ^ ( (1<<22) -1 ) )][22]<<" ";
        else
            cout<<"-1 ";
    }
    cout<<endl;
    return 0;
}


#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#ifndef ONLINE_JUDGE
    #include<lol.h>
#endif

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007

int dp[1ll<<22];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("/home/srinivas/Desktop/cp/input.txt","r",stdin);
        // freopen("/home/srinivas/Desktop/output.txt","w",stdout);
    #endif
    int n;
    cin>>n;
    int a[n];
    ifr(i,0,1<<22) dp[i]=-1;
    ifr(i,0,n) cin>>a[i],dp[a[i]]=a[i];
    ifr(i,0,22) {
        ifr(mask,0,1ll<<22) {
            if((mask>>i)&1)
                dp[mask]=max(dp[mask],dp[mask^(1ll<<i)]);
        }
    }
    int x = 1ll<<22;
    x-=1;
    ifr(i,0,n)
        cout<<dp[x^a[i]]<<" ";
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl '\n'
const int MX = (1<<20)+5;
int f[MX],ans[MX];
int32_t main(){
	fastio;
	int n;
	cin>>n;
	int a[n];
	memset(ans,-1,sizeof(ans));
	for(int i=0;i<n;i++){
		cin>>a[i];
		f[a[i]]++;
		ans[a[i]]=a[i];
	}
	for(int i=0;i<20;i++){
		for(int j=0;j<(1<<20);j++){
			if((j>>i)&1){
				f[j]+=f[j^(1<<i)];
				ans[j]=max(ans[j],ans[j^(1<<i)]);
			}
		}
	}
	for(int i=0;i<n;i++){
		cout<<ans[((1<<20)-1)^a[i]]<<" ";
	}
	cout<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl '\n'
const int MX = 1e7+5;
int f[MX],ans[MX];
int32_t main(){
	fastio;
	int n;
	cin>>n;
	int a[n];
	memset(ans,-1,sizeof(ans));
	for(int i=0;i<n;i++){
		cin>>a[i];
		f[a[i]]++;
		ans[a[i]]=a[i];
	}
	for(int i=0;i<20;i++){
		for(int j=0;j<(1<<20);j++){
			if((j>>i)&1){
				f[j]+=f[j^(1<<i)];
				ans[j]=max(ans[j],ans[j^(1<<i)]);
			}
		}
	}
	for(int i=0;i<n;i++){
		cout<<ans[((1<<20)-1)^a[i]]<<" ";
	}
	cout<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl '\n'

const int mx=(1<<22);
int f[mx],ans[mx];

int32_t main(){
	fastio;
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	memset(ans,-1,sizeof(ans));
	for(int i=0;i<n;i++){
		f[a[i]]++;
		ans[a[i]]=a[i];
	}
	for(int j=0;j<22;j++)
		for(int i=0;i<mx;i++)
			if(i&(1<<j)){
				f[i]+=f[i^(1<<j)];
				if(f[i^(1<<j)])
				ans[i]=ans[i^(1<<j)];
			}
	for(int i=0;i<n;i++){
		int p=(mx-1)&(~a[i]);
		cout<<ans[p]<<" ";
	}
	cout<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl '\n'
const int MX = (1<<22)+5;
int f[MX],ans[MX];
int32_t main(){
	fastio;
	int n;
	cin>>n;
	int a[n];
	memset(ans,-1,sizeof(ans));
	for(int i=0;i<n;i++){
		cin>>a[i];
		f[a[i]]++;
		ans[a[i]]=a[i];
	}
	for(int i=0;i<22;i++){
		for(int j=0;j<(1<<22);j++){
			if((j>>i)&1){
				f[j]+=f[j^(1<<i)];
				ans[j]=max(ans[j],ans[j^(1<<i)]);
			}
		}
	}
	for(int i=0;i<n;i++){
		cout<<ans[((1<<22)-1)^a[i]]<<" ";
	}
	cout<<endl;
}


#include<iostream>
using namespace std;
typedef long long int ll;
ll a[(1<<22)+10]={0},cache;
 ll f[(1<<22)+10];
 ll flip(ll a)
 {
 	ll pos=0,rval=0;int t=22;
	 while(t--)
 	{
 		if(a%2==0)rval+=(1<<pos);
 		a/=2;pos++;
	 }
	 return rval;
 }
int main()
{
	int n;ios_base::sync_with_stdio(false);
	//cout<<flip(90);
	//cout<<(flip(2008878)|(2185216));
	cin>>n;
    ll sr[n],temp=n;
    for(int i=0;i<n;i++){
	cin>>cache;a[cache]++;sr[i]=cache;}

    n=(1<<22)+10;

	for(int i=0;i<n;i++) if(a[i])f[i]=i;
	for(int bit=0;bit<22;bit++) for(int i=0;i<n;i++)  if(i&(1<<bit) && f[i^(1<<bit)]!=0)f[i]=f[i^(1<<bit)];
	//for(int i=0;i<10;i++) cout<<f[i]<<" ";
	 for(int i=0;i<temp;i++)if(f[flip(sr[i])])cout<<f[flip(sr[i])]<<" ";else cout<<"-1 ";
	cout<<endl;
	return 0;
}


#include<iostream>
using namespace std;
typedef long long int ll;
ll a[4000000+10]={0},cache;
 ll f[4000000+10];
 ll flip(ll a)
 {
 	ll pos=0,rval=0;int t=21;
	 while(t--)
 	{
 		if(a%2==0)rval+=(1<<pos);
 		a/=2;pos++;
	 }
	 return rval;
 }
int main()
{
	int n;
	//cout<<flip(90);
	cin>>n;
    ll sr[n],temp=n;
    for(int i=0;i<n;i++){
	cin>>cache;a[cache]++;sr[i]=cache;}

    n=4000000+10;

	for(int i=0;i<n;i++) if(a[i])f[i]=i;
	for(int bit=0;bit<22;bit++) for(int i=0;i<n;i++)  if(i&(1<<bit) && f[i^(1<<bit)]!=0)f[i]=f[i^(1<<bit)];
	//for(int i=0;i<10;i++) cout<<f[i]<<" ";
	 for(int i=0;i<temp;i++)if(f[flip(sr[i])])cout<<f[flip(sr[i])]<<" ";else cout<<"-1 ";
	cout<<endl;
	return 0;
}


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

ll a[4000000+10]={0},cache;
 ll f[4000000+10];
 ll baap;
 void compute()
 {
 	baap=0;
     baap=pow(2,21)-1;
 }
 ll flip(ll a)
 {
 	return a^baap;
	 ll pos=0,rval=0;int t=21;
	 while(t--)
 	{
 		if(a%2==0)rval+=(1<<pos);
 		a/=2;pos++;
	 }
	 return rval;
 }
int main()
{
	compute();
	int n;ios_base::sync_with_stdio(false);
//	cout<<flip(90);
	cin>>n;
    ll sr[n],temp=n;
    for(int i=0;i<n;i++){
	cin>>cache;a[cache]++;sr[i]=cache;f[cache]=cache;}

	n=4000000+10;
	for(int bit=0;bit<22;bit++) for(int i=0;i<n;i++) if(f[i]==0) if(i&(1<<bit) && f[i^(1<<bit)]!=0)f[i]=f[i^(1<<bit)];
	//for(int i=0;i<10;i++) cout<<f[i]<<" ";
	 for(int i=0;i<temp;i++)if(f[flip(sr[i])])cout<<f[flip(sr[i])]<<" ";else cout<<"-1 ";
	cout<<endl;
	return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
typedef long long int ll;
ll a[4000000+10]={0},cache;
 ll f[4000000+10];
 ll baap;
 void compute()
 {
 	baap=0;
     baap=pow(2,21)-1;
 }
 ll flip(ll a)
 {
 	return a^baap;
	 ll pos=0,rval=0;int t=21;
	 while(t--)
 	{
 		if(a%2==0)rval+=(1<<pos);
 		a/=2;pos++;
	 }
	 return rval;
 }
int main()
{
	compute();
	int n;
//	cout<<flip(90);
	cin>>n;
    ll sr[n],temp=n;
    for(int i=0;i<n;i++){
	cin>>cache;a[cache]++;sr[i]=cache;f[cache]=cache;}

	n=4000000+10;
	for(int bit=0;bit<22;bit++) for(int i=0;i<n;i++) if(f[i]==0) if(i&(1<<bit) && f[i^(1<<bit)]!=0)f[i]=f[i^(1<<bit)];
	//for(int i=0;i<10;i++) cout<<f[i]<<" ";
	 for(int i=0;i<temp;i++)if(f[flip(sr[i])])cout<<f[flip(sr[i])]<<" ";else cout<<"-1 ";
	cout<<endl;
	return 0;
}


#include<iostream>
using namespace std;
typedef long long int ll;
ll a[4000000+10]={0},cache;
 ll f[4000000+10];
 ll flip(ll a)
 {
 	ll pos=0,rval=0;int t=21;
	 while(t--)
 	{
 		if(a%2==0)rval+=(1<<pos);
 		a/=2;pos++;
	 }
	 return rval;
 }
int main()
{
	int n;ios_base::sync_with_stdio(false);
	//cout<<flip(90);
	cin>>n;
    ll sr[n],temp=n;
    for(int i=0;i<n;i++){
	cin>>cache;a[cache]++;sr[i]=cache;}

    n=4000000+10;

	for(int i=0;i<n;i++) if(a[i])f[i]=i;
	for(int bit=0;bit<22;bit++) for(int i=0;i<n;i++)  if(i&(1<<bit) && f[i^(1<<bit)]!=0)f[i]=f[i^(1<<bit)];
	//for(int i=0;i<10;i++) cout<<f[i]<<" ";
	 for(int i=0;i<temp;i++)if(f[flip(sr[i])])cout<<f[flip(sr[i])]<<" ";else cout<<"-1 ";
	cout<<endl;
	return 0;
}


#include<iostream>
using namespace std;
typedef long long int ll;
ll a[4000000+10]={0},cache;
 ll f[4000000+10];
 ll flip(ll a)
 {
 	ll pos=0,rval=0;int t=21;
	 while(t--)
 	{
 		if(a%2==0)rval+=(1<<pos);
 		a/=2;pos++;
	 }
	 return rval;
 }
int main()
{
	int n;
	//cout<<flip(90);
	cin>>n;
    ll sr[n],temp=n;
    for(int i=0;i<n;i++){
	cin>>cache;a[cache]++;sr[i]=cache;}

	for(int i=0;i<n;i++) f[sr[i]]=sr[i];
	n=4000000+10;
	for(int bit=0;bit<22;bit++) for(int i=0;i<n;i++) if(f[i]==0) if(i&(1<<bit) && f[i^(1<<bit)]!=0)f[i]=f[i^(1<<bit)];
	//for(int i=0;i<10;i++) cout<<f[i]<<" ";
	 for(int i=0;i<temp;i++)if(f[flip(sr[i])])cout<<f[flip(sr[i])]<<" ";else cout<<"-1 ";
	cout<<endl;
	return 0;
}


#include<iostream>
using namespace std;
typedef long long int ll;
ll a[4000000+10]={0},cache;
 ll f[4000000+10];
 ll flip(ll a)
 {
 	ll pos=0,rval=0;int t=21;
	 while(t--)
 	{
 		if(a%2==0)rval+=(1<<pos);
 		a/=2;pos++;
	 }
	 return rval;
 }
int main()
{
	int n;
	//cout<<flip(90);
	cin>>n;
    ll sr[n],temp=n;
    for(int i=0;i<n;i++){
	cin>>cache;a[cache]++;sr[i]=cache;f[cache]=cache;}

	n=4000000+10;
	for(int bit=0;bit<22;bit++) for(int i=0;i<n;i++) if(f[i]==0) if(i&(1<<bit) && f[i^(1<<bit)]!=0)f[i]=f[i^(1<<bit)];
	//for(int i=0;i<10;i++) cout<<f[i]<<" ";
	 for(int i=0;i<temp;i++)if(f[flip(sr[i])])cout<<f[flip(sr[i])]<<" ";else cout<<"-1 ";
	cout<<endl;
	return 0;
}


#include<iostream>
using namespace std;
typedef long long int ll;
ll a[4000000+10]={0},cache;
 ll f[4000000+10];
 ll flip(ll a)
 {
 	ll pos=0,rval=0;int t=21;
	 while(t--)
 	{
 		if(a%2==0)rval+=(1<<pos);
 		a/=2;pos++;
	 }
	 return rval;
 }
int main()
{
	int n;
	//cout<<flip(90);
	cin>>n;
    ll sr[n],temp=n;
    for(int i=0;i<n;i++){
	cin>>cache;a[cache]++;sr[i]=cache;}

	for(int i=0;i<n;i++) f[sr[i]]=sr[i];
	n=4000000+10;
	for(int bit=0;bit<22;bit++) for(int i=0;i<n;i++)  if(i&(1<<bit) && f[i^(1<<bit)]!=0)f[i]=f[i^(1<<bit)];
	//for(int i=0;i<10;i++) cout<<f[i]<<" ";
	 for(int i=0;i<temp;i++)if(f[flip(sr[i])])cout<<f[flip(sr[i])]<<" ";else cout<<"-1 ";
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
const long long int mod=1e9 +7;
ll n,nb=0,m,a[200005],k,red[4000005];
set <ll>st;
string s;
vector< ll >v[200005],v1;
ll dp[(1<<23)][25],dp2[(1<<23)];

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	ll i,j,x,y;
	//freopen("a.txt","r",stdin);
    	cin>>n;
    	memset(red,0,sizeof(red));
        for(i=0;i<n;i++){
        	cin>>a[i];
        	red[a[i]]++;
		}
        memset(dp,-1,sizeof(dp));
        memset(dp2,-1,sizeof(dp2));
        for(ll mask=0;mask<(1<<22);mask++)dp[mask][-1]=-1;
        for(ll mask = 0; mask<(1<<22); ++mask){
	            if(red[mask]!=0){
	            	//cout<<mask<<endl;
	            	dp[mask][-1]=mask;
				}
	             for(ll i = 0;i <=22; ++i){
		            if(mask & (1<<i))
		               	if(dp[mask][i-1]!=-1)dp[mask][i]=dp[mask][i-1];
						   else dp[mask][i] =dp[mask^(1<<i)][i-1];
	            	else
		            	dp[mask][i] = dp[mask][i-1];
        	    }
	            dp2[mask] = dp[mask][22];
        }
        for(i=0;i<n;i++)cout<<dp2[(1LL<<22)-1-a[i]]<<" ";
 }


#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
const long long int mod=1e9 +7;
ll n,nb=0,m,a[200005],k,red[4000005];
set <ll>st;
string s;
vector< ll >v[200005],v1;
ll dp[(1LL<<23)];

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	ll i,j,x,y;
//	freopen("a.txt","r",stdin);
    	cin>>n;
    	memset(red,0,sizeof(red));
        for(i=0;i<n;i++){
        	cin>>a[i];
        	red[a[i]]++;
		}
        for(ll mask= 0;mask<(1LL<<20); ++mask)dp[mask]=-1;
        for(ll mask= 0;mask<(1LL<<20); ++mask)
	             if(red[mask]!=0)dp[mask] =mask;
        for( i = 0;i<20; ++i) for(ll mask = 0; mask < (1LL<<20); ++mask){
	            if(mask & (1LL<<i))
		                if(dp[mask^(1LL<<i)]!=-1)dp[mask]=dp[mask^(1LL<<i)];
           }
        for(i=0;i<n;i++)cout<<dp[(1LL<<20)-1-a[i]]<<" ";
 }


#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
const long long int mod=1e9 +7;
ll n,nb=0,m,a[200005],k,red[4000005];
set <ll>st;
string s;
vector< ll >v[200005],v1;
ll dp[(1<<22)][25],dp2[(1<<22)];

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	ll i,j,x,y;
	//freopen("a.txt","r",stdin);
    	cin>>n;
    	memset(red,0,sizeof(red));
        for(i=0;i<n;i++){
        	cin>>a[i];
        	red[a[i]]++;
		}
        memset(dp,-1,sizeof(dp));
        memset(dp2,-1,sizeof(dp2));
        for(ll mask=0;mask<(1LL<<22);mask++)dp[mask][-1]=-1;
        for(ll mask = 0; mask<(1LL<<22); ++mask){
	            if(red[mask]!=0){
	            	//cout<<mask<<endl;
	            	dp[mask][-1]=mask;
				}
	             for(ll i = 0;i <=22; ++i){
		            if(mask & (1LL<<i))
		               	if(dp[mask][i-1]!=-1)dp[mask][i]=dp[mask][i-1];
						   else dp[mask][i] =dp[mask^(1LL<<i)][i-1];
	            	else
		            	dp[mask][i] = dp[mask][i-1];
        	    }
	            dp2[mask] = dp[mask][22];
        }
        for(i=0;i<n;i++)cout<<dp2[(1LL<<22)-1-a[i]]<<" ";
 }


#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
const long long int mod=1e9 +7;
ll n,nb=0,m,a[200005],k,red[4000005];
set <ll>st;
string s;
vector< ll >v[200005],v1;
ll dp[(1LL<<23)];

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	ll i,j,x,y;
	//freopen("a.txt","r",stdin);
    	cin>>n;
    	memset(red,0,sizeof(red));
        for(i=0;i<n;i++){
        	cin>>a[i];
        	red[a[i]]++;
		}
        for(ll mask= 0;mask<(1LL<<22); ++mask)dp[mask]=-1;
        for(ll mask= 0;mask<(1LL<<22); ++mask)
	             if(red[mask]!=0)dp[mask] =mask;
        for( i = 0;i<22; ++i) for(ll mask = 0; mask < (1LL<<22); ++mask){
	            if(mask & (1LL<<i))
		                if(dp[mask^(1LL<<i)]!=-1)dp[mask]=dp[mask^(1LL<<i)];
           }
        for(i=0;i<n;i++)cout<<dp[(1LL<<22)-1-a[i]]<<" ";
 }


#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
const long long int mod=1e9 +7;
ll n,nb=0,m,a[200005],k,red[4000005];
set <ll>st;
string s;
vector< ll >v[200005],v1;
ll dp[(1<<11)][25],dp2[(1<<11)];

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	ll i,j,x,y;
	//freopen("a.txt","r",stdin);
    	cin>>n;
    	memset(red,0,sizeof(red));
        for(i=0;i<n;i++){
        	cin>>a[i];
        	red[a[i]]++;
		}
        memset(dp,-1,sizeof(dp));
        memset(dp2,-1,sizeof(dp2));
        for(ll mask=0;mask<(1LL<<10);mask++)dp[mask][-1]=-1;
        for(ll mask = 0; mask<(1LL<<10); ++mask){
	            if(red[mask]!=0){
	            	//cout<<mask<<endl;
	            	dp[mask][-1]=mask;
				}
	             for(ll i = 0;i <=10; ++i){
		            if(mask & (1LL<<i))
		               	if(dp[mask][i-1]!=-1)dp[mask][i]=dp[mask][i-1];
						   else dp[mask][i] =dp[mask^(1LL<<i)][i-1];
	            	else
		            	dp[mask][i] = dp[mask][i-1];
        	    }
	            dp2[mask] = dp[mask][10];
        }
        for(i=0;i<n;i++)cout<<dp2[(1LL<<10)-1-a[i]]<<" ";
 }


#include<bits/stdc++.h>
using namespace std;
typedef long long  int ll;
const long long int mod=1e9 +7;
ll n,nb=0,m,a[2000005],k,red[10000005];
set <ll>st;
string s;
vector< ll >v[200005],v1;
ll dp[(1LL<<23)];

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	ll i,j,x,y;
	//freopen("a.txt","r",stdin);
    	cin>>n;
    	memset(red,0,sizeof(red));
        for(i=0;i<n;i++){
        	cin>>a[i];
        	red[a[i]]++;
		}
        for(ll mask= 0;mask<(1LL<<22); ++mask)dp[mask]=-1;
        for(ll mask= 0;mask<(1LL<<22); ++mask)
	             if(red[mask]!=0)dp[mask] =mask;
        for( i = 0;i<22; ++i) for(ll mask = 0; mask < (1LL<<22); ++mask){
	            if(mask & (1LL<<i))
		                if(dp[mask^(1LL<<i)]!=-1)dp[mask]=dp[mask^(1LL<<i)];
           }
        for(i=0;i<n;i++)cout<<dp[(1LL<<22)-1-a[i]]<<" ";
 }


#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
const long long int mod=1e9 +7;
ll n,nb=0,m,a[200005],k,red[4000005];
set <ll>st;
string s;
vector< ll >v[200005],v1;
ll dp[(1LL<<23)];

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	ll i,j,x,y;
	//freopen("a.txt","r",stdin);
    	cin>>n;
    	memset(red,0,sizeof(red));
        for(i=0;i<n;i++){
        	cin>>a[i];
        	red[a[i]]++;
		}
        memset(dp,-1,sizeof(dp));
        for(ll mask= 0;mask<(1<<23); ++mask)
	             if(red[mask]!=0)dp[mask] =mask;
        for( i = 0;i <23; ++i) for(ll mask = 0; mask < (1<<23); ++mask){
	            if(mask & (1<<i))
		                if(dp[mask^(1<<i)]!=-1)dp[mask]=dp[mask^(1<<i)];
           }
            for(i=0;i<n;i++)cout<<dp[(1LL<<23)-1-a[i]]<<" ";
 }


#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define x first
#define y second
#define deb(x) cout<< #x <<" "<<x<<"\n";
#define deb1(x,y) cout<< #x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sz(a) (int)a.size()
const ll MOD=1e9+7;
const int MAX=5e6+1;
const double EPS=1e-6;
int dcmp(double x,double y)
{return (fabs(x-y)<=EPS)?0:(x<y)?1:-1;}

int mask[MAX];
int main()
{
	ios
	///cout << fixed << setprecision(15);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	memset(mask,-1,sizeof mask);
	int n;
	cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mask[a[i]]=a[i];
	}
	for(int i=1;i<MAX;i++)
	{
		if(mask[i]!=-1)
		{
			for(int j=0;j<22;j++)
			{
				if((i&(1<<j))==0&&(mask[i|(1<<j)]==-1))
				{
					mask[i|(1<<j)]=max(mask[i|(1<<j)],mask[i]);
				}
			}
		}
	}
	vector<int>ans(MAX,-1);
	for(int i=0;i<n;i++)
	{
		int k=floor(log2(a[i]))+1;
		int num=((1<<k)-1)^a[i];
		ans[a[i]]=mask[num];

	}
	for(int i=0;i<n;i++)
	{
		if(ans[a[i]]!=-1)
		ans[ans[a[i]]]=a[i];

	}

	for(int i=0;i<n;i++)
		cout<<ans[a[i]]<<" ";

}


#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define x first
#define y second
#define deb(x) cout<< #x <<" "<<x<<"\n";
#define deb1(x,y) cout<< #x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sz(a) (int)a.size()
const ll MOD=1e9+7;
const int MAX=4e6+1;
const double EPS=1e-6;
int dcmp(double x,double y)
{return (fabs(x-y)<=EPS)?0:(x<y)?1:-1;}

int mask[MAX];
int main()
{
	ios
	///cout << fixed << setprecision(15);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	memset(mask,-1,sizeof mask);
	int n;
	cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mask[a[i]]=a[i];
	}
	for(int i=1;i<MAX;i++)
	{
		if(mask[i]!=-1)
		{
			for(int j=0;j<21;j++)
			{
				if((i&(1<<j))==0&&(mask[i|(1<<j)]==-1))
				{
					mask[i|(1<<j)]=max(mask[i|(1<<j)],mask[i]);
				}
			}
		}
	}
	vector<int>ans(MAX,-1);
	for(int i=0;i<n;i++)
	{
		int k=floor(log2(a[i]))+1;
		int num=((1<<k)-1)^a[i];
		ans[a[i]]=mask[num];

	}
	for(int i=0;i<n;i++)
	{
		if(ans[a[i]]!=-1)
		ans[ans[a[i]]]=a[i];

	}

	for(int i=0;i<n;i++)
		cout<<ans[a[i]]<<" ";

}


#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define x first
#define y second
#define deb(x) cout<< #x <<" "<<x<<"\n";
#define deb1(x,y) cout<< #x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sz(a) (int)a.size()
const ll MOD=1e9+7;
const int MAX=4e6+1;
const double EPS=1e-6;
int dcmp(double x,double y)
{return (fabs(x-y)<=EPS)?0:(x<y)?1:-1;}
#define maxBit 22
#define maxMask (1<<22)-1
int dp[maxMask];
int main()
{
	ios
	///cout << fixed << setprecision(15);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n;
	cin>>n;
	vector<int>a(n);
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++){cin>>a[i];dp[a[i]]=a[i];}
	for(int i=1;i<=maxMask;i++)
	{
		for(int j=0;j<maxBit;j++)
		{
			if(i&(1<<j)){
				dp[i]=max(dp[i^(1<<j)],dp[i]);
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		cout<<dp[((1<<maxBit)-1)^a[i]]<<" ";
	}

}


#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define x first
#define y second
#define deb(x) cout<< #x <<" "<<x<<"\n";
#define deb1(x,y) cout<< #x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sz(a) (int)a.size()
const ll MOD=1e9+7;
const int MAX=4e6+1;
const double EPS=1e-6;
int dcmp(double x,double y)
{return (fabs(x-y)<=EPS)?0:(x<y)?1:-1;}

int mask[MAX];
int main()
{
	ios
	///cout << fixed << setprecision(15);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	memset(mask,-1,sizeof mask);
	int n;
	cin>>n;
	vector<int>a(n);
	unordered_map<int,bool>mp;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mask[a[i]]=a[i];
		mp[a[i]]=true;
	}
	for(int i=1;i<MAX;i++)
	{
		if(mask[i]!=-1)
		{
			for(int j=0;j<21;j++)
			{
				if((i&(1<<j))==0&&(mask[i|(1<<j)]==-1))
				{
					mask[i|(1<<j)]=mask[i];
				}
			}
		}
	}
	vector<int>ans(MAX,-1);
	for(int i=0;i<n;i++)
	{
		int k=floor(log2(a[i]))+1;
		int num=((1<<k)-1)^a[i];
		ans[a[i]]=mask[num];

	}
	for(int i=0;i<n;i++)
	{
		if(ans[a[i]]!=-1)
		ans[ans[a[i]]]=a[i];

	}

	for(int i=0;i<n;i++)
		cout<<ans[a[i]]<<" ";

}


#include <bits/stdc++.h>
#define ls (u<<1)
#define rs (ls|1)
using namespace std;
const int NN=1000100;
int a[NN],mx[NN<<4],ans[NN];
void add(int u,int val,int lv){
	if(lv==22) {
		mx[u]=val;
		return;
	}
	if((val&(1<<lv))==0){
		add(ls,val,lv+1);
	}
	else {
		add(rs,val,lv+1);
	}
	mx[u]=max(mx[ls],mx[rs]);
}
int fl,vv;
int calc(int u,int val,int lv){
	if(lv==22) return 0;
	if((val/(1<<lv))==0){
		return mx[u];
	}
	if(val&(1<<lv)){
		return calc(ls,val,lv+1);
	}
	else {
		return max(calc(ls,val,lv+1),calc(rs,val,lv+1));
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i),add(1,a[i],0);
	for(int i=1;i<=n;i++){
		ans[i]=calc(1,a[i],0);
		if(!ans[i]) ans[i]=-1;
	}
	for(int i=1;i<=n;i++) {
		if(i>1) printf(" ");
		printf("%d",ans[i]);
	}
	return 0;
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define pb push_back
#define y second
#define x first

using namespace std;
using INT=long long;
using VI=vector<int>;
using pii=pair<int, int>;
template<typename A, typename B> void smin(A &a, const B &b) {if(a>b) a=b;}
template<typename A, typename B> void smax(A &a, const B &b) {if(a<b) a=b;}

int num[4194304];

#define NN 1010101

int a[NN], s[NN];

bool bit(int u, int x) {
	return (u>>x)&1;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n; scanf("%d", &n);
	for(int i=1; i<=n; i++) {
		scanf("%d", a+i);
		int s=0;
		for(int j=0; j<22; j++) if(!bit(a[i], j)) {
			s|=1<<j;
		}
		::s[i]=s, num[s]=a[i];
	}

	int ed=1<<22;
	for(int I=ed; I--; ) if(num[I]) {
		for(int j=0; j<22; j++) if(bit(I, j)) {
			num[I^(1<<j)]=num[I];
		}
	}

	for(int i=1; i<=n; i++) {
		int I=(ed-1)^s[i];
		if(num[I]) printf("%d ", num[I]);
		else printf("-1 ");
	}
}


#include<bits/stdc++.h>
#define NN 1000100

using namespace std;
using INT=long long ;

int dp[1<<22];
int a[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	cin>>n;
	for(int i=1; i<=n; i++)scanf("%d", &a[i]);
	int mx=1<<22;
	for(int i=1; i<=n; i++)dp[a[i]]=a[i];
	for(int i=1; i<mx; i++){
		if(dp[i])continue;
		for(int k=0; k<22; k++){
			int tmp=(1<<k);
			if((i&tmp)==tmp){
				if(dp[i^tmp]){
					dp[i]=dp[i^tmp];
					break;
				}
			}
		}
	}
	for(int i=1; i<=n; i++){
		int y=mx-1-a[i];
		if(dp[y])printf("%d ",dp[y]);
		else printf("-1 ");
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[1100000];
int b[4200000];
#define MX (1<<22)
int main(){
#ifndef ONLINE_JUDGE
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
#endif
	int n; scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]), b[a[i]] = a[i];
	for(int i = 0; i < MX; i++){
		for(int j = 0; j < 22; j++){
			if(i & (1 << j) && b[i ^ (1 << j)]){
				b[i] = b[(i ^ (1 << j))];
				break;
			}
		}
	}
	for(int i = 0; i < n; i++){
		if(i) printf(" ");
		if(b[a[i] ^ (MX - 1)]) printf("%d", b[a[i] ^ (MX - 1)]);
		else printf("-1");
	}printf("\n");
}


#include <bits/stdc++.h>
using namespace std;
const int NN=1000100;
const int MAX=1<<22;
int a[NN],b[MAX];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i),b[a[i]]=a[i];
	for(int i=1;i<MAX;i++){
		int fl=0;
		for(int j=0;j<22;j++){
			if((i&(1<<j)) and b[i^(1<<j)]) {b[i]=b[i^(1<<j)];break;}
		}
	}
	for(int i=1;i<=n;i++){
		if(b[(MAX-1)^a[i]]) printf("%d ",b[(MAX-1)^a[i]]);
		else printf("-1 ");
	}
	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 2000006;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

int dp[(1<<22) + 3];
int ans[(1<<22)+3],a[(1<<22)+3];
int m[(1<<22)+3];

void solve()
{
    ll i,j,n;
    int mask;

    set0(m);
    cin>>n;
    rep(i,n)
    {
        cin>>a[i];
        m[a[i]]++;
    }

    memset(dp,-1,sizeof(dp));
    memset(ans,-1,sizeof(ans));

    // ans array for storing possible number in a[nn] which is also a subset of mask
    for(mask=0;mask<(1<<22);mask++)
    {
        dp[mask]=m[mask];
        if(m[mask])
            ans[mask]=mask;
    }

    // put here max size of a[i] possible
    for(i=0;i<22;i++)
    {
        for(mask=0;mask<(1<<22);mask++)
        {
            if(mask&(1<<i))
            {
                if(i==0)
                {
                    dp[mask]+=m[mask^(1<<i)];
                    if(ans[mask]==-1 and m[mask^(1<<i)])
                        ans[mask]=mask^(1<<i);
                }
                else
                {
                    dp[mask]+=dp[mask^(1<<i)];
                    if(ans[mask]==-1 and dp[mask^(1<<i)])
                        ans[mask]=ans[mask^(1<<i)];
                }
            }
        }

    }

    int tmp = 0;

    for(i=0;i<n;i++)
    {
        tmp = 0;
        for(j=0;j<22;j++)
            if(!(a[i]&(1<<j)))
                tmp|=(1<<j);
        cout<<ans[tmp]<<" ";
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    // cin>>tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}


// DP Technique
// http://codeforces.com/blog/entry/45223

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 2000006;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

ll dp[(1<<22) + 3][23];
int a[1000006],ans[(1<<22)+3];
int m[(1<<22)+3];

void solve()
{
    ll i,j,n;
    int mask;

    set0(m);
    cin>>n;
    rep(i,n)
    {
        cin>>a[i];
        m[a[i]]++;
    }

    memset(dp,-1,sizeof(dp));
    memset(ans,-1,sizeof(ans));

    // put here max size of a[i] possible
    for(mask=0;mask<(1<<22);mask++)
    {
        for(i=0;i<22;i++)
        {
            if(i==0)
            {
                if(ans[mask]==-1)
                {
                    if(m[mask])
                        ans[mask]=mask;
                    else if(m[mask^(1<<i)])
                        ans[mask]=mask^(1<<i);
                }
                if(mask&(1<<i))
                    dp[mask][i] = m[mask] + m[mask^(1<<i)];
                else
                    dp[mask][i] = m[mask];
            }
            else
            {
                if(ans[mask]==-1)
                {
                    if(dp[mask][i-1])
                        ans[mask]=ans[mask];
                    else if(dp[mask^(1<<i)][i-1])
                        ans[mask]=ans[mask^(1<<i)];
                }

                if(mask&(1<<i))
                    dp[mask][i] = dp[mask][i-1] + dp[mask^(1<<i)][i-1];
                else
                    dp[mask][i] = dp[mask][i-1];
            }
        }
    }

    int tmp = 0;
    for(i=0;i<n;i++)
    {
        tmp = 0;
        for(j=0;j<22;j++)
            if(!(a[i]&(1<<j)))
                tmp|=(1<<j);
        //cout<<tmp<<" ";
       // cout<<dp[tmp][21]<<endl;
      // cout<<tmp<<" ";
        if(m[ans[tmp]]>0)
            cout<<ans[tmp]<<" ";
        else
            cout<<-1<<" ";
        //cout<<endl;
    }
    cout<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    // cin>>tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 2000006;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

ll dp[(1<<22) + 3][22];
int ans[(1<<22)+3];
int m[(1<<22)+3];

void solve()
{
    ll i,j,n;
    int mask;
    int a;
    set0(m);
    cin>>n;
    rep(i,n)
    {
        cin>>a;
        m[a]++;
    }

    memset(dp,-1,sizeof(dp));
    memset(ans,-1,sizeof(ans));

    // put here max size of a[i] possible
    for(mask=0;mask<(1<<22);mask++)
    {
        for(i=0;i<22;i++)
        {
            if(i==0)
            {
                if(ans[mask]==-1)
                {
                    if(m[mask])
                        ans[mask]=mask;
                    else if(m[mask^(1<<i)])
                        ans[mask]=mask^(1<<i);
                }
                if(mask&(1<<i))
                    dp[mask][i] = m[mask] + m[mask^(1<<i)];
                else
                    dp[mask][i] = m[mask];
            }
            else
            {
                if(ans[mask]==-1)
                {
                    if(dp[mask][i-1])
                        ans[mask]=ans[mask];
                    else if(dp[mask^(1<<i)][i-1])
                        ans[mask]=ans[mask^(1<<i)];
                }

                if(mask&(1<<i))
                    dp[mask][i] = dp[mask][i-1] + dp[mask^(1<<i)][i-1];
                else
                    dp[mask][i] = dp[mask][i-1];
            }
        }
    }

    int tmp = 0;
    for(i=0;i<n;i++)
    {
        tmp = 0;
        for(j=0;j<22;j++)
            if(!(a[i]&(1<<j)))
                tmp|=(1<<j);
        //cout<<tmp<<" ";
       // cout<<dp[tmp][21]<<endl;
      // cout<<tmp<<" ";
        //if(m[ans[tmp]]>0)
            cout<<ans[tmp]<<" ";
        //else
          //  cout<<-1<<" ";
        //cout<<endl;
    }
    cout<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    // cin>>tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 2000006;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

int dp[(1<<22) + 3][22];
int ans[(1<<22)+3],a[(1<<22)+3];
int m[(1<<22)+3];

void solve()
{
    ll i,j,n;
    int mask;

    set0(m);
    cin>>n;
    rep(i,n)
    {
        cin>>a[i];
        m[a[i]]++;
    }

    memset(dp,-1,sizeof(dp));
    memset(ans,-1,sizeof(ans));

    // put here max size of a[i] possible
    for(mask=0;mask<(1<<22);mask++)
    {
        for(i=0;i<22;i++)
        {
            if(i==0)
            {
                if(ans[mask]==-1)
                {
                    if(m[mask])
                        ans[mask]=mask;
                    else if(m[mask^(1<<i)])
                        ans[mask]=mask^(1<<i);
                }
                if(mask&(1<<i))
                    dp[mask][i] = m[mask] + m[mask^(1<<i)];
                else
                    dp[mask][i] = m[mask];
            }
            else
            {
                if(ans[mask]==-1)
                {
                    if(dp[mask][i-1])
                        ans[mask]=ans[mask];
                    else if(dp[mask^(1<<i)][i-1])
                        ans[mask]=ans[mask^(1<<i)];
                }

                if(mask&(1<<i))
                    dp[mask][i] = dp[mask][i-1] + dp[mask^(1<<i)][i-1];
                else
                    dp[mask][i] = dp[mask][i-1];
            }
        }
    }

    int tmp = 0;
    for(i=0;i<n;i++)
    {
        tmp = 0;
        for(j=0;j<22;j++)
            if(!(a[i]&(1<<j)))
                tmp|=(1<<j);
        //cout<<tmp<<" ";
       // cout<<dp[tmp][21]<<endl;
      // cout<<tmp<<" ";
        //if(m[ans[tmp]]>0)
            cout<<ans[tmp]<<" ";
        //else
          //  cout<<-1<<" ";
        //cout<<endl;
    }
    cout<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    // cin>>tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}


// DP Technique
// http://codeforces.com/blog/entry/45223

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 2000006;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

ll dp[(1<<22) + 5][23];
int a[nn],ans[3*nn];
int m[3*nn];

void solve()
{
    ll i,j,n;
    int mask;

    set0(m);
    cin>>n;
    rep(i,n)
    {
        cin>>a[i];
        m[a[i]]++;
    }

    memset(dp,-1,sizeof(dp));
    memset(ans,-1,sizeof(ans));

    // put here max size of a[i] possible
    for(mask=0;mask<(1<<22);mask++)
    {
        for(i=0;i<22;i++)
        {
            if(i==0)
            {
                if(ans[mask]==-1)
                {
                    if(m[mask])
                        ans[mask]=mask;
                    else if(m[mask^(1<<i)])
                        ans[mask]=mask^(1<<i);
                }
                if(mask&(1<<i))
                    dp[mask][i] = m[mask] + m[mask^(1<<i)];
                else
                    dp[mask][i] = m[mask];
            }
            else
            {
                if(ans[mask]==-1)
                {
                    if(dp[mask][i-1])
                        ans[mask]=ans[mask];
                    else if(dp[mask^(1<<i)][i-1])
                        ans[mask]=ans[mask^(1<<i)];
                }

                if(mask&(1<<i))
                    dp[mask][i] = dp[mask][i-1] + dp[mask^(1<<i)][i-1];
                else
                    dp[mask][i] = dp[mask][i-1];
            }
        }
    }

    int tmp = 0;
    for(i=0;i<n;i++)
    {
        tmp = 0;
        for(j=0;j<22;j++)
            if(!(a[i]&(1<<j)))
                tmp|=(1<<j);
        //cout<<tmp<<" ";
       // cout<<dp[tmp][21]<<endl;
      // cout<<tmp<<" ";
        //if(m[ans[tmp]]>0)
            cout<<ans[tmp]<<" ";
        //else
         //   cout<<-1<<" ";
        //cout<<endl;
    }
    cout<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    // cin>>tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;

#define ll long long int
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)

#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)

#define swap(a,b){ auto _t=a;a=b,b=_t;}
// typedef __int128 bign;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define MD          1000000007
#define M 			1000011
#define LN 			14
#define fftmod      998244353
#define EPS         (double)1e-10

ll md=MD;
ll inf=2e18;

inline ll exp(ll a,ll b){ll r=1LL;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}

using cd=complex<double>;
const double PI=acos(-1);

vii g[M];
ll dp[1ll<<22][23];
bitset<1ll<<22> bt;
ll a[M];

int main(){

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,x,y,n,s,z,p,k,T;string s1,s2;x=1;ll q;
    cin>>n;
    unordered_map<int,int> ans;
    ll N=22;
    lp(1,n)cin>>a[i],bt[a[i]]=1;
    for(ll mask=0;mask<(1<<N);++mask){
        dp[mask][0]=-1;
        if(bt[mask])dp[mask][0]=mask;;
        for(i=1;i<=N;++i){
            if(mask&(1ll<<(i-1))){
                if(dp[mask][i-1]>0)dp[mask][i]=dp[mask][i-1];
                if(dp[mask^(1ll<<(i-1))][i-1]>0)dp[mask][i]=dp[mask^(1ll<<(i-1))][i-1];

            }
            else{
                if(dp[mask][i-1]>0)
                    dp[mask][i]=dp[mask][i-1];
            }
        }

        if(dp[mask][N]>0)ans[mask]=dp[mask][N];

    }
    ll fo=(1ll<<22)-1;
    lp(1,n){
        if(ans.find(fo^a[i])!=ans.end())cout<<ans[fo^a[i]]<<" ";
        else cout<<"-1 ";
    }
    cout<<"\n";

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;

#define ll long long int
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)

#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)

#define swap(a,b){ auto _t=a;a=b,b=_t;}
// typedef __int128 bign;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define MD          1000000007
#define M 			1000011
#define LN 			14
#define fftmod      998244353
#define EPS         (double)1e-10

ll md=MD;
ll inf=2e18;

inline ll exp(ll a,ll b){ll r=1LL;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}

using cd=complex<double>;
const double PI=acos(-1);

vii g[M];
ll dp[1ll<<22][24];
ll a[M];

int main(){

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,x,y,n,s,z,p,k,T;string s1,s2;x=1;ll q;
    cin>>n;
    unordered_map<ll,ll> mp;
    unordered_map<int,int> ans;
    ll N=22;
    lp(1,n)cin>>a[i],++mp[a[i]];
    for(ll mask=0;mask<(1<<N);++mask){
        dp[mask][0]=-1;
        if(mp.find(mask)!=mp.end())dp[mask][0]=mask;
        for(i=1;i<=N;++i){
            if(mask&(1ll<<(i-1))){
                if(dp[mask][i-1]>0)dp[mask][i]=dp[mask][i-1];
                if(dp[mask^(1ll<<(i-1))][i-1]>0)dp[mask][i]=dp[mask^(1ll<<(i-1))][i-1];

            }
            else{
                if(dp[mask][i-1]>0)
                    dp[mask][i]=dp[mask][i-1];
            }
        }

        if(dp[mask][N]>0)ans[mask]=dp[mask][N];

    }
    ll fo=(1ll<<22)-1;
    lp(1,n){
        if(ans.find(fo^a[i])!=ans.end())cout<<ans[fo^a[i]]<<" ";
        else cout<<"-1 ";
    }
    cout<<"\n";

    return 0;
}