#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#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/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define lld long double

#define data sdadsd

//#define int lll

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 2e5 + 229;
const lll M = 1e9 + 7;
const lll M2 = 1e9 + 9;
const lll mod = 998244353;
const int rx[4] = {0, 0, -1, 1};
const int ry[4] = {-1, 1, 0, 0};
const lld eps = 1e-11;
const double pi = acos(-1.0);

vector < vector < int > > bor;

vector < int > kek;

vector < int > what;

int a[N];

void add(vector < int > x, int mask) {
    int v = 0;
    for (auto to : x) {
        if (!bor[v][to]) {
            bor[v][to] = int(bor.size());
            bor.pb(kek);
            what.pb(0);
        }
        v = bor[v][to];
        what[v] = mask;
    }
}

int ok(vector < int > x) {
    int v = 0;
    for (auto to : x) {
        if (!bor[v][to]) {
            return -1;
        }
        v = bor[v][to];
    }
    return what[v];
}

int kol (int x) {
    int res = 0;
    while (x) {
        if (x % 2) {
            ++res;
        }
        x /= 2;
    }
    return res;
}

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("maxxor.in", "r", stdin);
//    freopen("maxxor.out", "w", stdout);
#endif
    kek.resize(31);
    what.pb(0);
    bor.pb(kek);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector < int > now(n);
    int k;
    int bit;
    for (int mask = 0; mask < (1 << 15); ++mask) {
        for (int i = 0; i < n; ++i) {
            k = 0;
            for (int j = 0; j < 15; ++j) {
                bit = ((1 << j) & a[i]);
                if (bit) {
                    bit = 1;
                }
                if ((1 << j) & mask) {
                    bit ^= 1;
                }
                if (bit) {
                    ++k;
                }
            }
            now[i] = k;
        }
        add(now, mask);
    }
    vector < int > need(n);
    bool f;
    int ans;
    int was = -1, hoho;
    for (int mask = 0; mask < (1 << 15); ++mask) {
        for (int i = 0; i < n; ++i) {
            k = 0;
            for (int j = 0; j < 15; ++j) {
                bit = ((1 << (j + 15)) & a[i]);
                if (bit) {
                    bit = 1;
                }
                if ((1 << j) & mask) {
                    bit ^= 1;
                }
                if (bit) {
                    ++k;
                }
            }
            now[i] = k;
        }
        for (k = 0; k < 30; ++k) {
            f = 0;
            for (int i = 0; i < n; ++i) {
                need[i] = k - now[i];
                if (need[i] < 0) {
                    f = 1;
                    break;
                }
            }
            if (!f) {
                ans = ok(need);
                if (ans != -1) {
                    int mem = mask + ans;
                    for (int i = 0; i < n; ++i) {
                        hoho = kol(a[i] ^ mem);
                        if (was == -1) {
                            was = hoho;
                        }
                        if (hoho != was) {
                            was = -2;
                        }
                    }
                    if (was == -2) {
                        continue;
                    }
                    was = -1;
                    cout << mask + ans;
                    return 0;
                }
            }
        }

    }
    cout << -1;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#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/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define lld long double

#define data sdadsd

//#define int lll

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 2e5 + 229;
const lll M = 1e9 + 7;
const lll M2 = 1e9 + 9;
const lll mod = 998244353;
const int rx[4] = {0, 0, -1, 1};
const int ry[4] = {-1, 1, 0, 0};
const lld eps = 1e-11;
const double pi = acos(-1.0);

vector < vector < int > > bor;

vector < int > kek;

vector < int > what;

int a[N];

void add(vector < int > x, int mask) {
    int v = 0;
    for (auto to : x) {
        if (!bor[v][to]) {
            bor[v][to] = int(bor.size());
            bor.pb(kek);
            what.pb(0);
        }
        v = bor[v][to];
        what[v] = mask;
    }
}

int ok(vector < int > x) {
    int v = 0;
    for (auto to : x) {
        if (!bor[v][to]) {
            return -1;
        }
        v = bor[v][to];
    }
    return what[v];
}

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("maxxor.in", "r", stdin);
//    freopen("maxxor.out", "w", stdout);
#endif
    kek.resize(31);
    what.pb(0);
    bor.pb(kek);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector < int > now(n);
    int k;
    int bit;
    for (int mask = 0; mask < (1 << 15); ++mask) {
        for (int i = 0; i < n; ++i) {
            k = 0;
            for (int j = 0; j < 15; ++j) {
                bit = ((1 << j) & a[i]);
                if (bit) {
                    bit = 1;
                }
                if ((1 << j) & mask) {
                    bit ^= 1;
                }
                if (bit) {
                    ++k;
                }
            }
            now[i] = k;
        }
        add(now, mask);
    }
    vector < int > need(n);
    bool f;
    int ans;
    for (int mask = 0; mask < (1 << 15); ++mask) {
        for (int i = 0; i < n; ++i) {
            k = 0;
            for (int j = 0; j < 15; ++j) {
                bit = ((1 << (j + 15)) & a[i]);
                if (bit) {
                    bit = 1;
                }
                if ((1 << j) & mask) {
                    bit ^= 1;
                }
                if (bit) {
                    ++k;
                }
            }
            now[i] = k;
        }
        for (k = 0; k < 30; ++k) {
            f = 0;
            for (int i = 0; i < n; ++i) {
                need[i] = k - now[i];
                if (need[i] < 0) {
                    f = 1;
                    break;
                }
            }
            if (!f) {
                ans = ok(need);
                if (ans != -1) {
                    cout << mask + ans;
                    return 0;
                }
            }
        }

    }
    cout << -1;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#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/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define lld long double

#define data sdadsd

//#define int lll

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 2e5 + 229;
const lll M = 1e9 + 7;
const lll M2 = 1e9 + 9;
const lll mod = 998244353;
const int rx[4] = {0, 0, -1, 1};
const int ry[4] = {-1, 1, 0, 0};
const lld eps = 1e-11;
const double pi = acos(-1.0);

vector < vector < int > > bor;

vector < int > kek;

vector < int > what;

int a[N];

void add(vector < int > x, int mask) {
    int v = 0;
    for (auto to : x) {
        if (!bor[v][to]) {
            bor[v][to] = int(bor.size());
            bor.pb(kek);
            what.pb(0);
        }
        v = bor[v][to];
        what[v] = mask;
    }
}

int ok(vector < int > x) {
    int v = 0;
    for (auto to : x) {
        if (!bor[v][to]) {
            return -1;
        }
        v = bor[v][to];
    }
    return what[v];
}

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("maxxor.in", "r", stdin);
//    freopen("maxxor.out", "w", stdout);
#endif
    kek.resize(31);
    what.pb(0);
    bor.pb(kek);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector < int > now(n);
    int k;
    int bit;
    for (int mask = 0; mask < (1 << 15); ++mask) {
        for (int i = 0; i < n; ++i) {
            k = 0;
            for (int j = 0; j < 15; ++j) {
                bit = ((1 << j) & a[i]);
                if (bit) {
                    bit = 1;
                }
                if ((1 << j) & mask) {
                    bit ^= 1;
                }
                if (bit) {
                    ++k;
                }
            }
            now[i] = k;
        }
        add(now, mask);
    }
    vector < int > need(n);
    bool f;
    int ans;
    for (int mask = 0; mask < (1 << 15); ++mask) {
        for (int i = 0; i < n; ++i) {
            k = 0;
            for (int j = 0; j < 15; ++j) {
                bit = ((1 << (j + 15)) & a[i]);
                if (bit) {
                    bit = 1;
                }
                if ((1 << j) & mask) {
                    bit ^= 1;
                }
                if (bit) {
                    ++k;
                }
            }
            now[i] = k;
        }
        for (k = 0; k <= 30; ++k) {
            f = 0;
            for (int i = 0; i < n; ++i) {
                need[i] = k - now[i];
                if (need[i] < 0) {
                    f = 1;
                    break;
                }
            }
            if (!f) {
                ans = ok(need);
                if (ans != -1) {
                    cout << mask + ans;
                    return 0;
                }
            }
        }

    }
    cout << -1;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#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/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define lld long double

#define data sdadsd

//#define int lll

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 2e5 + 229;
const lll M = 1e9 + 7;
const lll M2 = 1e9 + 9;
const lll mod = 998244353;
const int rx[4] = {0, 0, -1, 1};
const int ry[4] = {-1, 1, 0, 0};
const lld eps = 1e-11;
const double pi = acos(-1.0);

vector < vector < int > > bor;

vector < int > kek;

vector < int > what;

int a[N];

void add(vector < int > x, int mask) {
    int v = 0;
    for (auto to : x) {
        if (!bor[v][to]) {
            bor[v][to] = int(bor.size());
            bor.pb(kek);
            what.pb(0);
        }
        v = bor[v][to];
        what[v] = mask;
    }
}

int ok(vector < int > x) {
    int v = 0;
    for (auto to : x) {
        if (!bor[v][to]) {
            return -1;
        }
        v = bor[v][to];
    }
    return what[v];
}

int kol (int x) {
    int res = 0;
    while (x) {
        if (x % 2) {
            ++res;
        }
        x /= 2;
    }
    return res;
}

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("maxxor.in", "r", stdin);
//    freopen("maxxor.out", "w", stdout);
#endif
    kek.resize(31);
    what.pb(0);
    bor.pb(kek);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector < int > now(n);
    int k;
    int bit;
    for (int mask = 0; mask < (1 << 15); ++mask) {
        for (int i = 0; i < n; ++i) {
            k = 0;
            for (int j = 0; j < 15; ++j) {
                bit = ((1 << j) & a[i]);
                if (bit) {
                    bit = 1;
                }
                if ((1 << j) & mask) {
                    bit ^= 1;
                }
                if (bit) {
                    ++k;
                }
            }
            now[i] = k;
        }
        add(now, mask);
    }
    vector < int > need(n);
    bool f;
    int ans;
    for (int mask = 0; mask < (1 << 15); ++mask) {
        for (int i = 0; i < n; ++i) {
            k = 0;
            for (int j = 0; j < 15; ++j) {
                bit = ((1 << (j + 15)) & a[i]);
                if (bit) {
                    bit = 1;
                }
                if ((1 << j) & mask) {
                    bit ^= 1;
                }
                if (bit) {
                    ++k;
                }
            }
            now[i] = k;
        }
        for (k = 0; k <= 30; ++k) {
            f = 0;
            for (int i = 0; i < n; ++i) {
                need[i] = k - now[i];
                if (need[i] < 0) {
                    f = 1;
                    break;
                }
            }
            if (!f) {
                ans = ok(need);
                if (ans != -1) {
                    for (int i = 0; i < 15; ++i) {
                        if ((1 << i) & mask) {
                            ans += (1 << (i + 15));
                        }
                    }
                    cout << ans;
                    return 0;
                }
            }
        }

    }
    cout << -1;
    return 0;
}


/*mjytxdy!*/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define inl inline
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,r,l) for(int i=(r);i>=(l);i--)
#define travel(i,u) for(int i=head[u];i;i=e[i].next)
#define lb(x) ((x)&(-(x)))
#define lson root<<1
#define rson root<<1|1
#define Mid (l+r>>1)
#define debug(x) cout<<#x":"<<x<<'\n'
#define myput puts("QaQ")
#define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
const int MAXN = 110;
int n,opt=2,sum,ans,a[MAXN],cnt[MAXN];
inl char read(){
	static const int IO_LEN=1024*1024;
	static char buf[IO_LEN],*ioh,*iot;
	if(ioh==iot){
		iot=(ioh=buf)+fread(buf,1,IO_LEN,stdin);
		if(ioh==iot) return -1;
	}
	return *ioh++;
}
template<class T>inl void read(T &x){
	static int iosig;static char ioc;
	for(iosig=0,ioc=read();!isdigit(ioc);ioc=read()) if(ioc=='-') iosig=1;
	for(x=0;isdigit(ioc);ioc=read())x=(x<<1)+(x<<3)+(ioc^'0');
	if(iosig) x=-x;
}
int main(){
	//freopen("in.txt","r",stdin);
	read(n);
	rep(i,1,n)read(a[i]),cnt[i]=__builtin_popcount(a[i]),opt=min(opt,cnt[i]);
	rep(i,1,n)if((cnt[i]-opt)&1) return puts("-1")&0;
	rep(i,0,29){
		bool tmp=0;
		rep(j,1,n) tmp|=((a[j]>>i)&1);
		sum+=tmp;
	}sum>>=1;
	rep(i,0,29){
		int tmp=0;
		rep(j,1,n)tmp+=((a[j]>>i)&1);
		if(!((tmp-opt)&1)) {
			rep(j,1,n)a[j]^=(1<<i);
			rep(j,1,n)cnt[j]=__builtin_popcount(a[j]),opt=min(opt,cnt[j]);
			ans|=1<<i;sum--;
		}
	}printf("%d\n",ans);//debug((43^12)),debug((12^12));
	return 0;
}


/*mjytxdy!*/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define inl inline
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,r,l) for(int i=(r);i>=(l);i--)
#define travel(i,u) for(int i=head[u];i;i=e[i].next)
#define lb(x) ((x)&(-(x)))
#define lson root<<1
#define rson root<<1|1
#define Mid (l+r>>1)
#define debug(x) cout<<#x":"<<x<<'\n'
#define myput puts("QaQ")
#define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
const int MAXN = 110;
int n,opt=2,sum,ans,a[MAXN],cnt[MAXN];
inl char read(){
	static const int IO_LEN=1024*1024;
	static char buf[IO_LEN],*ioh,*iot;
	if(ioh==iot){
		iot=(ioh=buf)+fread(buf,1,IO_LEN,stdin);
		if(ioh==iot) return -1;
	}
	return *ioh++;
}
template<class T>inl void read(T &x){
	static int iosig;static char ioc;
	for(iosig=0,ioc=read();!isdigit(ioc);ioc=read()) if(ioc=='-') iosig=1;
	for(x=0;isdigit(ioc);ioc=read())x=(x<<1)+(x<<3)+(ioc^'0');
	if(iosig) x=-x;
}
map<vector<int>,int> Map;
int main(){
	//freopen("in.txt","r",stdin);
	read(n);
	rep(i,1,n)read(a[i]);
	rep(i,0,(1<<15)-1){
		static vector<int> mjy;
		mjy.clear();
		const int tmp=__builtin_popcount((a[1]&(1<<15)-1)^i);
		rep(j,2,n) mjy.pb(__builtin_popcount((a[j]&(1<<15)-1)^i)-tmp);
		Map[mjy]=i;
	}
	rep(i,0,(1<<15)-1){
		static vector<int> mjy;
		mjy.clear();
		const int tmp=__builtin_popcount((a[1]>>15)^i);
		rep(j,2,n) mjy.pb(-__builtin_popcount((a[j]>>15)^i)+tmp);
		if(Map[mjy]) return printf("%d\n",(i<<15)+Map[mjy])&0;
	}puts("-1");
	return 0;
}


/*mjytxdy!*/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define inl inline
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,r,l) for(int i=(r);i>=(l);i--)
#define travel(i,u) for(int i=head[u];i;i=e[i].next)
#define lb(x) ((x)&(-(x)))
#define lson root<<1
#define rson root<<1|1
#define Mid (l+r>>1)
#define debug(x) cout<<#x":"<<x<<'\n'
#define myput puts("QaQ")
#define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
const int MAXN = 110;
int n,opt=2,sum,ans,a[MAXN],cnt[MAXN];
inl char read(){
	static const int IO_LEN=1024*1024;
	static char buf[IO_LEN],*ioh,*iot;
	if(ioh==iot){
		iot=(ioh=buf)+fread(buf,1,IO_LEN,stdin);
		if(ioh==iot) return -1;
	}
	return *ioh++;
}
template<class T>inl void read(T &x){
	static int iosig;static char ioc;
	for(iosig=0,ioc=read();!isdigit(ioc);ioc=read()) if(ioc=='-') iosig=1;
	for(x=0;isdigit(ioc);ioc=read())x=(x<<1)+(x<<3)+(ioc^'0');
	if(iosig) x=-x;
}
map<vector<int>,int> Map;
int main(){
//	freopen("in.txt","r",stdin);
	read(n);
	rep(i,1,n)read(a[i]);
	rep(i,0,(1<<15)-1){
		static vector<int> mjy;
		mjy.clear();
		const int tmp=__builtin_popcount((a[1]&(1<<15)-1)^i);
		rep(j,2,n) mjy.pb(__builtin_popcount((a[i]&(1<<15)-1)^i)-tmp);
		Map[mjy]=i;
	}
	rep(i,0,(1<<15)-1){
		static vector<int> mjy;
		mjy.clear();
		const int tmp=__builtin_popcount((a[1]>>15)^i);
		rep(i,2,n) mjy.pb(-__builtin_popcount((a[i]>>15)^i)+tmp);
		if(Map[mjy]) return printf("%d\n",(i<<15)+Map[mjy]);
	}puts("-1");
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define sci(a) scanf("%lld",&a)
#define scii(a,b) scanf("%lld%lld",&a,&b)
#define sciii(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define pri(a) printf("%lld",a)
#define prc(a) printf("%c",a)
#define prs() printf(" ")
#define prn() printf("\n")
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define each(i,a) for(auto i=a.begin();i!=a.end();++i)
#define mkp make_pair
#define fst first
#define snd second
#define frt front
#define bak back
#define pub(a) push_back(a)
#define pob() pop_back
#define puf(a) push_front(a)
#define pof() pop_front
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define nmsl cout<<"NMSL"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define FAST ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
#define endl '\n'
using namespace std;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<db,int> pdi;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef vector<char> vec;
typedef vector<string> ves;
typedef map<int,int> mpii;
typedef map<pii,int> mppi;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> dqi;
typedef deque<pii> dqp;
typedef deque<char> dqc;
typedef deque<string> dqs;
typedef priority_queue<int> mxpi;
typedef priority_queue<int,vei,greater<int>> mnpi;
typedef priority_queue<pii> mxpp;
typedef priority_queue<pii,vep,greater<pii>> mnpp;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const db eps=1e-10;
const db pi=3.1415926535;
int lowb(int x){return x&-x;}
int mmax(int a,int b,int c){return max(max(a,b),c);}
int mmin(int a,int b,int c){return min(min(a,b),c);}
int count2(int x){return __builtin_popcountll(x);}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
bool bigeql(db a,db b){if(a>b||fabs(a-b)<=eps)return true;return false;}
bool eql(db a,db b){if(fabs(a-b)<eps) return 1;return 0;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
int gcd(int x,int y){return __gcd(x,y);}
int lcm(int x,int y){return x*y/__gcd(x,y);}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}
int qpow(int a,int b,int mod){int tmp=a%mod,ans=1;while(b){if(b&1) ans=(ans*tmp)%mod;tmp=(tmp*tmp)%mod;b>>=1;}return ans;}
inline int read(){char ch=getchar();int s=0,w=1;while(ch<48||ch>57){if(ch=='-')w=-1;ch=getchar();}while(ch>=48&&ch<=57){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}return s*w;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+48);}

int n,a[105];
int lim=(1LL<<16);
map<vei,int> mp;

signed main(){
	FAST
    cin>>n;re(i,1,n) cin>>a[i];
    fo(mask,0,lim){
		vei v(n+1,0);
		re(i,1,n) v[i]=count2(a[i]^mask);
		mp[v]=mask;
	}
	//lower
	fo(mask,0,lim){
		vei v1(n+1,0),v2(n+1,0);
		int mx=0;
		re(i,1,n){
			v1[i]=count2((a[i]>>15)^mask);
			mx=max(mx,v1[i]);
		}
		for(int t=mx;t<=30;++t){
			re(i,1,n) v2[i]=t-v1[i];
			auto it=mp.find(v2);
			if(it!=mp.end()){
				cout<<(it->snd|(mask<<15));
				return 0;
			}
		}
	}
	//upper
	cout<<-1;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define sci(a) scanf("%lld",&a)
#define scii(a,b) scanf("%lld%lld",&a,&b)
#define sciii(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define pri(a) printf("%lld",a)
#define prc(a) printf("%c",a)
#define prs() printf(" ")
#define prn() printf("\n")
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define each(i,a) for(auto i=a.begin();i!=a.end();++i)
#define mkp make_pair
#define fst first
#define snd second
#define frt front
#define bak back
#define pub(a) push_back(a)
#define pob() pop_back
#define puf(a) push_front(a)
#define pof() pop_front
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define nmsl cout<<"NMSL"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define FAST ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
#define endl '\n'
using namespace std;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<db,int> pdi;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef vector<char> vec;
typedef vector<string> ves;
typedef map<int,int> mpii;
typedef map<pii,int> mppi;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> dqi;
typedef deque<pii> dqp;
typedef deque<char> dqc;
typedef deque<string> dqs;
typedef priority_queue<int> mxpi;
typedef priority_queue<int,vei,greater<int>> mnpi;
typedef priority_queue<pii> mxpp;
typedef priority_queue<pii,vep,greater<pii>> mnpp;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const db eps=1e-10;
const db pi=3.1415926535;
int lowb(int x){return x&-x;}
int mmax(int a,int b,int c){return max(max(a,b),c);}
int mmin(int a,int b,int c){return min(min(a,b),c);}
int count2(int x){return __builtin_popcountll(x);}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
bool bigeql(db a,db b){if(a>b||fabs(a-b)<=eps)return true;return false;}
bool eql(db a,db b){if(fabs(a-b)<eps) return 1;return 0;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
int gcd(int x,int y){return __gcd(x,y);}
int lcm(int x,int y){return x*y/__gcd(x,y);}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}
int qpow(int a,int b,int mod){int tmp=a%mod,ans=1;while(b){if(b&1) ans=(ans*tmp)%mod;tmp=(tmp*tmp)%mod;b>>=1;}return ans;}
inline int read(){char ch=getchar();int s=0,w=1;while(ch<48||ch>57){if(ch=='-')w=-1;ch=getchar();}while(ch>=48&&ch<=57){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}return s*w;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+48);}

int n,a[105];
int lim=(1LL<<15);
map<vei,int> mp;

signed main(){
	FAST
    cin>>n;re(i,1,n) cin>>a[i];
    fo(mask,0,lim){
		vei v(n+1);
		re(i,1,n) v[i]=count2(a[i]^mask);
		mp[v]=mask;
	}
	//lower
	fo(mask,0,lim){
		vei v1(n+1),v2(n+1);
		int mx=0;
		re(i,1,n){
			v1[i]=count2((a[i]>>15)^mask);
			mx=max(mx,v1[i]);
		}
		for(int t=mx;t<=30;++t){
			re(i,1,n) v2[i]=t-v1[i];
			auto it=mp.find(v2);
			if(it!=mp.end()){
				cout<<(it->snd^(mask<<15));
				return 0;
			}
		}
	}
	//upper
	cout<<-1;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define sci(a) scanf("%lld",&a)
#define scii(a,b) scanf("%lld%lld",&a,&b)
#define sciii(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define pri(a) printf("%lld",a)
#define prc(a) printf("%c",a)
#define prs() printf(" ")
#define prn() printf("\n")
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define each(i,a) for(auto i=a.begin();i!=a.end();++i)
#define mkp make_pair
#define fst first
#define snd second
#define frt front
#define bak back
#define pub(a) push_back(a)
#define pob() pop_back
#define puf(a) push_front(a)
#define pof() pop_front
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define nmsl cout<<"NMSL"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define FAST ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
#define endl '\n'
using namespace std;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<db,int> pdi;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef vector<char> vec;
typedef vector<string> ves;
typedef map<int,int> mpii;
typedef map<pii,int> mppi;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> dqi;
typedef deque<pii> dqp;
typedef deque<char> dqc;
typedef deque<string> dqs;
typedef priority_queue<int> mxpi;
typedef priority_queue<int,vei,greater<int>> mnpi;
typedef priority_queue<pii> mxpp;
typedef priority_queue<pii,vep,greater<pii>> mnpp;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const db eps=1e-10;
const db pi=3.1415926535;
int lowb(int x){return x&-x;}
int mmax(int a,int b,int c){return max(max(a,b),c);}
int mmin(int a,int b,int c){return min(min(a,b),c);}
int count2(int x){return __builtin_popcountll(x);}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
bool bigeql(db a,db b){if(a>b||fabs(a-b)<=eps)return true;return false;}
bool eql(db a,db b){if(fabs(a-b)<eps) return 1;return 0;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
int gcd(int x,int y){return __gcd(x,y);}
int lcm(int x,int y){return x*y/__gcd(x,y);}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}
int qpow(int a,int b,int mod){int tmp=a%mod,ans=1;while(b){if(b&1) ans=(ans*tmp)%mod;tmp=(tmp*tmp)%mod;b>>=1;}return ans;}
inline int read(){char ch=getchar();int s=0,w=1;while(ch<48||ch>57){if(ch=='-')w=-1;ch=getchar();}while(ch>=48&&ch<=57){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}return s*w;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+48);}

int n,a[35];
int lim=(1LL<<15);
map<vei,int> mp;

signed main(){
	FAST
    cin>>n;re(i,1,n) cin>>a[i];
    fo(mask,0,lim){
		vei v(n+1);
		re(i,1,n) v[i]=count2(a[i]^mask);
		mp[v]=mask;
	}
	//lower
	fo(mask,0,lim){
		vei v1(n+1),v2(n+1);
		int mx=0;
		re(i,1,n){
			v1[i]=count2((a[i]>>15)^mask);
			mx=max(mx,v1[i]);
		}
		for(int t=mx;t<=30;++t){
			re(i,1,n) v2[i]=t-v1[i];
			auto it=mp.find(v2);
			if(it!=mp.end()){
				cout<<(it->snd^(mask<<15));
				return 0;
			}
		}
	}
	//upper
	cout<<-1;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define sci(a) scanf("%lld",&a)
#define scii(a,b) scanf("%lld%lld",&a,&b)
#define sciii(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define pri(a) printf("%lld",a)
#define prc(a) printf("%c",a)
#define prs() printf(" ")
#define prn() printf("\n")
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define each(i,a) for(auto i=a.begin();i!=a.end();++i)
#define mkp make_pair
#define fst first
#define snd second
#define frt front
#define bak back
#define pub(a) push_back(a)
#define pob() pop_back
#define puf(a) push_front(a)
#define pof() pop_front
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define nmsl cout<<"NMSL"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define FAST ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
#define endl '\n'
using namespace std;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<db,int> pdi;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef vector<char> vec;
typedef vector<string> ves;
typedef map<int,int> mpii;
typedef map<pii,int> mppi;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> dqi;
typedef deque<pii> dqp;
typedef deque<char> dqc;
typedef deque<string> dqs;
typedef priority_queue<int> mxpi;
typedef priority_queue<int,vei,greater<int>> mnpi;
typedef priority_queue<pii> mxpp;
typedef priority_queue<pii,vep,greater<pii>> mnpp;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const db eps=1e-10;
const db pi=3.1415926535;
int lowb(int x){return x&-x;}
int mmax(int a,int b,int c){return max(max(a,b),c);}
int mmin(int a,int b,int c){return min(min(a,b),c);}
int count2(int x){return __builtin_popcountll(x);}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
bool bigeql(db a,db b){if(a>b||fabs(a-b)<=eps)return true;return false;}
bool eql(db a,db b){if(fabs(a-b)<eps) return 1;return 0;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
int gcd(int x,int y){return __gcd(x,y);}
int lcm(int x,int y){return x*y/__gcd(x,y);}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}
int qpow(int a,int b,int mod){int tmp=a%mod,ans=1;while(b){if(b&1) ans=(ans*tmp)%mod;tmp=(tmp*tmp)%mod;b>>=1;}return ans;}
inline int read(){char ch=getchar();int s=0,w=1;while(ch<48||ch>57){if(ch=='-')w=-1;ch=getchar();}while(ch>=48&&ch<=57){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}return s*w;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+48);}

int n,a[105];
int lim=(1LL<<15);
map<vei,int> mp;

signed main(){
	FAST
    cin>>n;re(i,1,n) cin>>a[i];
    fo(mask,0,lim){
		vei v(n+1,0);
		re(i,1,n) v[i]=count2(a[i]^mask);
		mp[v]=mask;
	}
	//lower
	fo(mask,0,lim){
		vei v1(n+1,0),v2(n+1,0);
		int mx=0;
		re(i,1,n){
			v1[i]=count2((a[i]>>15)^mask);
			mx=max(mx,v1[i]);
		}
		for(int t=mx;t<=30;++t){
			re(i,1,n) v2[i]=t-v1[i];
			auto it=mp.find(v2);
			if(it!=mp.end()){
				cout<<(it->snd|(mask<<15));
				return 0;
			}
		}
	}
	//upper
	cout<<-1;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define sci(a) scanf("%lld",&a)
#define scii(a,b) scanf("%lld%lld",&a,&b)
#define sciii(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define pri(a) printf("%lld",a)
#define prc(a) printf("%c",a)
#define prs() printf(" ")
#define prn() printf("\n")
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define each(i,a) for(auto i=a.begin();i!=a.end();++i)
#define mkp make_pair
#define fst first
#define snd second
#define frt front
#define bak back
#define pub(a) push_back(a)
#define pob() pop_back
#define puf(a) push_front(a)
#define pof() pop_front
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define nmsl cout<<"NMSL"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define FAST ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
#define endl '\n'
using namespace std;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<db,int> pdi;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef vector<char> vec;
typedef vector<string> ves;
typedef map<int,int> mpii;
typedef map<pii,int> mppi;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> dqi;
typedef deque<pii> dqp;
typedef deque<char> dqc;
typedef deque<string> dqs;
typedef priority_queue<int> mxpi;
typedef priority_queue<int,vei,greater<int>> mnpi;
typedef priority_queue<pii> mxpp;
typedef priority_queue<pii,vep,greater<pii>> mnpp;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const db eps=1e-10;
const db pi=3.1415926535;
int lowb(int x){return x&-x;}
int mmax(int a,int b,int c){return max(max(a,b),c);}
int mmin(int a,int b,int c){return min(min(a,b),c);}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
bool bigeql(db a,db b){if(a>b||fabs(a-b)<=eps)return true;return false;}
bool eql(db a,db b){if(fabs(a-b)<eps) return 1;return 0;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
int gcd(int x,int y){return __gcd(x,y);}
int lcm(int x,int y){return x*y/__gcd(x,y);}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}
int qpow(int a,int b,int mod){int tmp=a%mod,ans=1;while(b){if(b&1) ans=(ans*tmp)%mod;tmp=(tmp*tmp)%mod;b>>=1;}return ans;}
inline int read(){char ch=getchar();int s=0,w=1;while(ch<48||ch>57){if(ch=='-')w=-1;ch=getchar();}while(ch>=48&&ch<=57){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}return s*w;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+48);}

int n,a[35];
int lim=(1LL<<15);
map<vei,int> mp;

signed main(){
	FAST
    cin>>n;re(i,1,n) cin>>a[i];
    fo(mask,0,lim){
		vei v(n+1);
		re(i,1,n) v[i]=__builtin_popcountll(a[i]^mask);
		mp[v]=mask;
	}
	//lower
	fo(mask,0,lim){
		vei v1(n+1),v2(n+1);
		int mx=0;
		re(i,1,n){
			v1[i]=__builtin_popcountll(a[i]^(mask<<15));
			mx=max(mx,v1[i]);
		}
		for(int t=mx;t<=30;++t){
			re(i,1,n) v2[i]=t-v1[i];
			auto it=mp.find(v2);
			if(it!=mp.end()){
				cout<<(it->snd^(mask<<15));
				return 0;
			}
		}
	}
	//upper
	cout<<-1;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define sci(a) scanf("%lld",&a)
#define scii(a,b) scanf("%lld%lld",&a,&b)
#define sciii(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define pri(a) printf("%lld",a)
#define prc(a) printf("%c",a)
#define prs() printf(" ")
#define prn() printf("\n")
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define each(i,a) for(auto i=a.begin();i!=a.end();++i)
#define mkp make_pair
#define fst first
#define snd second
#define frt front
#define bak back
#define pub(a) push_back(a)
#define pob() pop_back
#define puf(a) push_front(a)
#define pof() pop_front
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define nmsl cout<<"NMSL"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define FAST ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
#define endl '\n'
using namespace std;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<db,int> pdi;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef vector<char> vec;
typedef vector<string> ves;
typedef map<int,int> mpii;
typedef map<pii,int> mppi;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> dqi;
typedef deque<pii> dqp;
typedef deque<char> dqc;
typedef deque<string> dqs;
typedef priority_queue<int> mxpi;
typedef priority_queue<int,vei,greater<int>> mnpi;
typedef priority_queue<pii> mxpp;
typedef priority_queue<pii,vep,greater<pii>> mnpp;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const db eps=1e-10;
const db pi=3.1415926535;
int lowb(int x){return x&-x;}
int mmax(int a,int b,int c){return max(max(a,b),c);}
int mmin(int a,int b,int c){return min(min(a,b),c);}
int count2(int x){return __builtin_popcountll(x);}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
bool bigeql(db a,db b){if(a>b||fabs(a-b)<=eps)return true;return false;}
bool eql(db a,db b){if(fabs(a-b)<eps) return 1;return 0;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
int gcd(int x,int y){return __gcd(x,y);}
int lcm(int x,int y){return x*y/__gcd(x,y);}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}
int qpow(int a,int b,int mod){int tmp=a%mod,ans=1;while(b){if(b&1) ans=(ans*tmp)%mod;tmp=(tmp*tmp)%mod;b>>=1;}return ans;}
inline int read(){char ch=getchar();int s=0,w=1;while(ch<48||ch>57){if(ch=='-')w=-1;ch=getchar();}while(ch>=48&&ch<=57){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}return s*w;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+48);}

int n,a[105];
int lim=(1LL<<15);
map<vei,int> mp;

signed main(){
	FAST
    cin>>n;re(i,1,n) cin>>a[i];
    fo(mask,0,lim){
		vei v(n+1,0);
		re(i,1,n) v[i]=count2(a[i]^mask);
		mp[v]=mask;
	}
	//lower
	fo(mask,0,lim){
		vei v1(n+1,0),v2(n+1,0);
		int mx=0;
		re(i,1,n){
			v1[i]=count2((a[i]>>15)^mask);
			mx=max(mx,v1[i]);
		}
		for(int t=mx;t<=30;++t){
			re(i,1,n) v2[i]=t-v1[i];
			auto it=mp.find(v2);
			if(it!=mp.end()){
				cout<<(it->snd^(mask<<15));
				return 0;
			}
		}
	}
	//upper
	cout<<-1;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define sci(a) scanf("%lld",&a)
#define scii(a,b) scanf("%lld%lld",&a,&b)
#define sciii(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define pri(a) printf("%lld",a)
#define prc(a) printf("%c",a)
#define prs() printf(" ")
#define prn() printf("\n")
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define each(i,a) for(auto i=a.begin();i!=a.end();++i)
#define mkp make_pair
#define fst first
#define snd second
#define frt front
#define bak back
#define pub(a) push_back(a)
#define pob() pop_back
#define puf(a) push_front(a)
#define pof() pop_front
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define nmsl cout<<"NMSL"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define FAST ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
#define endl '\n'
using namespace std;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<db,int> pdi;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef vector<char> vec;
typedef vector<string> ves;
typedef map<int,int> mpii;
typedef map<pii,int> mppi;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> dqi;
typedef deque<pii> dqp;
typedef deque<char> dqc;
typedef deque<string> dqs;
typedef priority_queue<int> mxpi;
typedef priority_queue<int,vei,greater<int>> mnpi;
typedef priority_queue<pii> mxpp;
typedef priority_queue<pii,vep,greater<pii>> mnpp;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const db eps=1e-10;
const db pi=3.1415926535;
int lowb(int x){return x&-x;}
int mmax(int a,int b,int c){return max(max(a,b),c);}
int mmin(int a,int b,int c){return min(min(a,b),c);}
int count2(int x){return __builtin_popcountll(x);}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
bool bigeql(db a,db b){if(a>b||fabs(a-b)<=eps)return true;return false;}
bool eql(db a,db b){if(fabs(a-b)<eps) return 1;return 0;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
int gcd(int x,int y){return __gcd(x,y);}
int lcm(int x,int y){return x*y/__gcd(x,y);}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}
int qpow(int a,int b,int mod){int tmp=a%mod,ans=1;while(b){if(b&1) ans=(ans*tmp)%mod;tmp=(tmp*tmp)%mod;b>>=1;}return ans;}
inline int read(){char ch=getchar();int s=0,w=1;while(ch<48||ch>57){if(ch=='-')w=-1;ch=getchar();}while(ch>=48&&ch<=57){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}return s*w;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+48);}

int n,a[105];
int lim=(1LL<<15);
map<vei,int> mp;

signed main(){
	FAST
    cin>>n;re(i,1,n) cin>>a[i];
    fo(mask,0,lim){
		vei v(n+1,0);
		re(i,1,n) v[i]=count2((a[i]&(lim-1))^mask);
		mp[v]=mask;
	}
	//lower
	fo(mask,0,lim){
		vei v1(n+1,0),v2(n+1,0);
		int mx=0;
		re(i,1,n){
			v1[i]=count2((a[i]>>15)^mask);
			mx=max(mx,v1[i]);
		}
		for(int t=mx;t<=30;++t){
			re(i,1,n) v2[i]=t-v1[i];
			auto it=mp.find(v2);
			if(it!=mp.end()){
				cout<<(it->snd|(mask<<15));
				return 0;
			}
		}
	}
	//upper
	cout<<-1;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define sci(a) scanf("%lld",&a)
#define scii(a,b) scanf("%lld%lld",&a,&b)
#define sciii(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scc(a) scanf("%c",&a)
#define scs(a) scanf("%s",a)
#define pri(a) printf("%lld",a)
#define prc(a) printf("%c",a)
#define prs() printf(" ")
#define prn() printf("\n")
#define re(i,a,b) for(int i=a;i<=b;++i)
#define fo(i,a,b) for(int i=a;i<b;++i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define each(i,a) for(auto i=a.begin();i!=a.end();++i)
#define mkp make_pair
#define fst first
#define snd second
#define frt front
#define bak back
#define pub(a) push_back(a)
#define pob() pop_back
#define puf(a) push_front(a)
#define pof() pop_front
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define nmsl cout<<"NMSL"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define FAST ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
#define endl '\n'
using namespace std;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<db,int> pdi;
typedef vector<int> vei;
typedef vector<pii> vep;
typedef vector<char> vec;
typedef vector<string> ves;
typedef map<int,int> mpii;
typedef map<pii,int> mppi;
typedef map<char,int> mpci;
typedef map<string,int> mpsi;
typedef deque<int> dqi;
typedef deque<pii> dqp;
typedef deque<char> dqc;
typedef deque<string> dqs;
typedef priority_queue<int> mxpi;
typedef priority_queue<int,vei,greater<int>> mnpi;
typedef priority_queue<pii> mxpp;
typedef priority_queue<pii,vep,greater<pii>> mnpp;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const db eps=1e-10;
const db pi=3.1415926535;
int lowb(int x){return x&-x;}
int mmax(int a,int b,int c){return max(max(a,b),c);}
int mmin(int a,int b,int c){return min(min(a,b),c);}
int count2(int x){return __builtin_popcountll(x);}
int ll(int p){return p<<1;}
int rr(int p){return p<<1|1;}
int mm(int l,int r){return (l+r)/2;}
int lg(int x){if(x==0) return 1;return (int)log2(x)+1;}
bool smleql(db a,db b){if(a<b||fabs(a-b)<=eps)return true;return false;}
bool bigeql(db a,db b){if(a>b||fabs(a-b)<=eps)return true;return false;}
bool eql(db a,db b){if(fabs(a-b)<eps) return 1;return 0;}
db len(db a,db b,db c,db d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}
int gcd(int x,int y){return __gcd(x,y);}
int lcm(int x,int y){return x*y/__gcd(x,y);}
bool isp(int x){if(x==1)return false;if(x==2)return true;for(int i=2;i*i<=x;++i)if(x%i==0)return false;return true;}
int qpow(int a,int b,int mod){int tmp=a%mod,ans=1;while(b){if(b&1) ans=(ans*tmp)%mod;tmp=(tmp*tmp)%mod;b>>=1;}return ans;}
inline int read(){char ch=getchar();int s=0,w=1;while(ch<48||ch>57){if(ch=='-')w=-1;ch=getchar();}while(ch>=48&&ch<=57){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}return s*w;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+48);}

int n,a[105];
int lim=(1LL<<16);
map<vei,int> mp;

signed main(){
	FAST
    cin>>n;re(i,1,n) cin>>a[i];
    fo(mask,0,lim){
		vei v(n+1);
		re(i,1,n) v[i]=count2(a[i]^mask);
		mp[v]=mask;
	}
	//lower
	fo(mask,0,lim){
		vei v1(n+1),v2(n+1);
		int mx=0;
		re(i,1,n){
			v1[i]=count2((a[i]>>15)^mask);
			mx=max(mx,v1[i]);
		}
		for(int t=mx;t<=30;++t){
			re(i,1,n) v2[i]=t-v1[i];
			auto it=mp.find(v2);
			if(it!=mp.end()){
				cout<<(it->snd^(mask<<15));
				return 0;
			}
		}
	}
	//upper
	cout<<-1;
	return 0;
}


/*
ID: leezhen
TASK: practice
LANG: C++11
*/
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define inf 1e9
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)

// struct

// data
int n;
int a[110];
int cnt[110];
int tmpcnt[110];
const int seed = 13;

ll getHash() {
  ll ret = 0;
  REP(i, 0, n) { ret = ret * seed + cnt[i]; }
  return ret;
}

void solve() {
  map<ll, int> mem;
  REP(i, 0, 1 << 15) {
    REP(j, 0, n) {
      int t = a[j] & ((1 << 15) - 1);
      cnt[j] = __builtin_popcount(t ^ i);
    }
    ll h = getHash();
    mem[h] = i;
  }
  REP(i, 0, 1 << 15) {
    REP(j, 0, n) {
      int t = (a[j] >> 15);
      tmpcnt[j] = __builtin_popcount(t ^ i);
    }
    REP(j, 0, 30) {
      bool f = true;
      REP(k, 0, n) {
        cnt[k] = j - tmpcnt[k];
        if (cnt[k] < 0) {
          f = false;
          break;
        }
      }
      if (!f) continue;
      ll h = getHash();
      if (mem.find(h) != mem.end()) {
        int ans = (i << 15) + mem[h];
        printf("%d\n", ans);
        int x = __builtin_popcount(ans ^ a[0]);
        REP(j, 0, n) {
          if (x != __builtin_popcount(ans ^ a[i])) {
            printf("failed\n");
            break;
          }
        }
        return;
      }
    }
  }
  printf("-1\n");
}

int main() {
  int k, kase = 0;
  // scanf("%d", &k);
  k = 1;
  while (k--) {
    scanf("%d", &n);
    REP(i, 0, n) scanf("%d", &a[i]);
    solve();
  }

  return 0;
}


/*
ID: leezhen
TASK: practice
LANG: C++11
*/
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef unsigned long long ull;
#define mp make_pair
#define pb push_back
#define inf 1e9
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)

// struct

// data
int n;
int a[110];
int cnt[110];
int tmpcnt[110];
const int seed = 13;

unsigned long long getHash() {
  unsigned long long ret = 0;
  REP(i, 0, n) { ret = ret * seed + cnt[i]; }
  return ret;
}

void solve() {
  map<ull, int> mem;
  REP(i, 0, 1 << 15) {
    REP(j, 0, n) {
      int t = a[j] & ((1 << 15) - 1);
      cnt[j] = __builtin_popcount(t ^ i);
    }
    ull h = getHash();
    mem[h] = i;
  }
  REP(i, 0, 1 << 15) {
    REP(j, 0, n) {
      int t = (a[j] >> 15);
      tmpcnt[j] = __builtin_popcount(t ^ i);
    }
    REP(j, 0, 30) {
      bool f = true;
      REP(k, 0, n) {
        cnt[k] = j - tmpcnt[k];
        if (cnt[k] < 0) {
          f = false;
          break;
        }
      }
      if (!f) continue;
      ull h = getHash();
      if (mem.find(h) != mem.end()) {
        int ans = (i << 15) + mem[h];
        printf("%d\n", ans);
        int x = __builtin_popcount(ans ^ a[0]);
        REP(j, 0, n) {
          if (x != __builtin_popcount(ans ^ a[j])) {
            printf("failed\n");
            break;
          }
        }
        return;
      }
    }
  }
  printf("-1\n");
}

int main() {
  int k, kase = 0;
  // scanf("%d", &k);
  k = 1;
  while (k--) {
    scanf("%d", &n);
    REP(i, 0, n) scanf("%d", &a[i]);
    solve();
  }

  return 0;
}


/*
ID: leezhen
TASK: practice
LANG: C++11
*/
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef unsigned long long ull;
#define mp make_pair
#define pb push_back
#define inf 1e9
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)

// struct

// data
int n;
int a[110];
int cnt[110];
int tmpcnt[110];
const int seed = 13;

unsigned long long getHash() {
  unsigned long long ret = 0;
  REP(i, 0, n) { ret = ret * seed + cnt[i]; }
  return ret;
}

void solve() {
  map<ull, int> mem;
  REP(i, 0, 1 << 15) {
    REP(j, 0, n) {
      int t = a[j] & ((1 << 15) - 1);
      cnt[j] = __builtin_popcount(t ^ i);
    }
    ull h = getHash();
    mem[h] = i;
  }
  REP(i, 0, 1 << 15) {
    REP(j, 0, n) {
      int t = (a[j] >> 15);
      tmpcnt[j] = __builtin_popcount(t ^ i);
    }
    REP(j, 0, 30) {
      bool f = true;
      REP(k, 0, n) {
        cnt[k] = j - tmpcnt[k];
        if (cnt[k] < 0) {
          f = false;
          break;
        }
      }
      if (!f) continue;
      ull h = getHash();
      if (mem.find(h) != mem.end()) {
        int ans = (i << 15) + mem[h];
        printf("%d\n", ans);
        int x = __builtin_popcount(ans ^ a[0]);
        REP(j, 0, n) {
          if (x != __builtin_popcount(ans ^ a[i])) {
            printf("failed\n");
            break;
          }
        }
        return;
      }
    }
  }
  printf("-1\n");
}

int main() {
  int k, kase = 0;
  // scanf("%d", &k);
  k = 1;
  while (k--) {
    scanf("%d", &n);
    REP(i, 0, n) scanf("%d", &a[i]);
    solve();
  }

  return 0;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int n;
int a[110];
int jl,bj;
vector<int> vp;
map<vector<int>,int> mp;
int main() {
	cin>>n;
	for(int x=1; x<=n; x++) {
		cin>>a[x];
	}
	for(int x=0; x<(1<<15); x++) {
		vp.clear();
		for(int y=1; y<=n; y++) {
			jl=0;
			for(int z=0; z<15; z++) {
				if(((a[y]>>z)&1)^((x>>z)&1)) {
					jl++;
				}
			}
			vp.push_back(jl);
		}
		for(int y=n-1; y>=0; y--) {
			vp[y]-=vp[0];
		}
		mp[vp]=x+1;
	}
	for(int x=0; x<(1<<15); x++) {
		vp.clear();
		for(int y=1; y<=n; y++) {
			jl=0;
			for(int z=0; z<15; z++) {
				if(((a[y]>>(z+15))&1)^((x>>z)&1)) {
					jl++;
				}
			}
			vp.push_back(jl);
		}
		for(int y=n-1; y>=0; y--) {
			vp[y]=vp[0]-vp[y];
		}
		if(mp[vp]) {
			cout<<(mp[vp]-1)+(x<<15)<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
}


#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

int main()
{
	int n,a[1000],b[1000],t=0,d=0;

	cin >> n;

	for (int i=0 ; i<n ; i++)
	{
		cin >> a[i] >> b[i];
	}

	for (int i=0 ; i<n ; i++)
	{
		if (a[i]!=b[i])
		{
			d = 2;
			break;
		}
	}

	for (int i=0 ; i<n-1 ; i++)
	{
		for (int j=i+1 ; j<n ; j++)
		{
			if (a[i]<a[j] || b[i]<b[j])
			{
				t = 1;
				break;
			}
		}
	}

	if (t==0 && d==0)
		cout << "maybe";
	if (t==1 && d==0)
		cout << "unrated";
	if (d==2)
		cout << "rated";
}


#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

int main()
{
	int n,a[1000],b[1000],t=0,d=0;

	cin >> n;

	for (int i=0 ; i<n ; i++)
	{
		cin >> a[i] >> b[i];
	}

	for (int i=0 ; i<n ; i++)
	{
		if (a[i]!=b[i])
		{
			d = 2;
			break;
		}
	}

	for (int i=0 ; i<n-1 ; i++)
	{
		for (int j=i+1 ; j<n ; j++)
		{
			if (a[i]<a[j] || b[i]<b[j])
			{
				t = 1;
				break;
			}
		}
	}

	if (t==0)
		cout << "maybe";
	if (t==1 && d==0)
		cout << "unrated";
	if (d==2)
		cout << "rated";
}


#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

int main()
{
	int n,a[1000],b[1000],t=0,d=0;

	cin >> n;

	for (int i=0 ; i<n ; i++)
	{
		cin >> a[i] >> b[i];
	}

	for (int i=0 ; i<n ; i++)
	{
		if (a[i]!=b[i])
		{
			d = 2;
			break;
		}
	}

	for (int i=0 ; i<n-1 ; i++)
	{
		for (int j=i+1 ; j<n ; j++)
		{
			if (a[i]<a[j])
			{
				t = 1;
				break;
			}
		}
	}

	if (t==0)
		cout << "maybe";
	if (t==1 && d==0)
		cout << "unrated";
	if (d==2)
		cout << "rated";
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iostream>
#include<map>
#include<queue>
using namespace std;

int a[1005];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        map<int,int>m;
        int x,y,flag=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&x,&y);
            if(x!=y)
            {
                flag=1;
            }
            if(x==y&&m[x])
            {
                flag=2;
            }
            m[x]++;
            m[y]++;
        }
        if(flag==0)
        {
            printf("unrated\n");
        }
        else if(flag==1)
        {
            printf("rated\n");
        }
        else
        {
            printf("maybe\n");
        }
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iostream>
#include<map>
#include<queue>
using namespace std;

int a[1005],b[1005];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        map<int,int>m;
        int flag=0,flag2=0;
        for(int i=1; i<=n; i++)
        {
            scanf("%d%d",&a[i],&b[i]);
            if(a[i]!=b[i])
            {
                flag=1;
            }
            if(i!=1&&a[i]>a[i-1])flag2=1;
        }
        if(flag==1)
        {
            printf("rated\n");
        }
        else
        {
            if(flag2==1)
                printf("unrated\n");
            else
            {
                printf("maybe\n");
            }
        }
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){

    int a[1000];
    int b[1000];
    int n;

    cin >> n;

    bool check = false;

    for (int i = 0;i<n; ++i) {
        cin >> a[i] >> b[i];
        if (a[i] != b[i]) {
            check = true;
            break;
        }
    }

    if (check == true) cout << "rated";
    else {
        sort(a,a+n);
        for (int i = 0;i<n; ++i) {
            if (a[i] != b[i]) {
                cout << "unrated";
                check = true;
                break;
            }
        }
        if (check == false) cout << "maybe";

    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){

    int a[1000];
    int b[1000];
    int n;

    cin >> n;

    bool check = false;

    for (int i = 0;i<n; ++i) {
        cin >> a[i] >> b[i];
        if (a[i] != b[i]) {
            check = true;
            break;
        }
    }

    if (check == true) cout << "rated";
    else {
        sort(a,a+n);
        for (int i = 0;i<n; ++i) {
            if (a[n-i-1] != b[i]) {
                cout << "unrated";
                check = true;
                break;
            }
        }
        if (check == false) cout << "maybe";

    }
    return 0;
}


#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	int lastScore = 2e9;
	bool isUnrated = false;

	for (int i = 0; i < n; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		if (a != b) {
			printf("rated\n");
			return 0;
		}
		else if (a > lastScore) {
			isUnrated = true;
		}
		lastScore = a;
	}

	if (isUnrated) {
		printf("unrated\n");
	}
	else {
		printf("maybe\n");
	}

	return 0;
}


#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	int lastScore = 2e9;

	for (int i = 0; i < n; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		if (a != b) {
			printf("rated\n");
			return 0;
		}
		else if (a > lastScore) {
			printf("unrated\n");
			return 0;
		}
		lastScore = a;
	}

	printf("maybe\n");

	return 0;
}


#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define loop(i,n)  for(int i =0;i<n;i++)

void main()
{
	int n;
	cin >> n;
	int aOld, aNew, bOld, bNew;
	bool d = true;

	cin >> aOld >> bOld;
	if (bOld - aOld != 0)
	{
		cout << "rated";
		return;
	}
	for (int i = 1; i < n; i++)
	{
		cin >> aNew >> bNew;
		if (bNew - aNew != 0)
		{
			cout << "rated";
			return;
		}

		if ((aNew - aOld) > 0)
			d = false;

		aOld = aNew;
		bOld = bNew;
	}
	if (d)
		cout << "maybe";
	else
		cout << "unrated";

	/*A. I Wanna Be the Guy*/
	/*
	int n;
	cin >> n;

	int* num = new int[2*n];

	loop(i, 2*n)
		num[i] = 0;
	string xname;

	while (getline(cin,  xname))
	{
		istringstream ss(xname) ;

	}

	int ns;
	loop(i, 2*n)
	{
		ns = 0;
		if (!(cin >> xname))
		{
			break;
		}
		num[ns] = ns;
	}

	for (int i = 1; i < 2 * n; i++)
	{
		if (num[i] != i)

		{
			cout << "Oh, my keyboard!";
			return;
		}
}
	cout << "I become the guy.";*/
}


#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define loop(i,n)  for(int i =0;i<n;i++)

void main()
{
	int n;
	cin >> n;
	int aOld, aNew, bOld, bNew;
	bool d = true;

	cin >> aOld >> aOld;
	if (bOld - aOld != 0)
	{
		cout << "rated";
		return;
	}
	for (int i = 1; i < n; i++)
	{
		cin >> aNew >> bNew;
		if (bNew - aNew != 0)
		{
			cout << "rated";
			return;
		}

		if (aNew - aOld > 0)
			d = false;

	}
	if (d)
		cout << "unrated";
	else
		cout << "maybe";

	/*A. I Wanna Be the Guy*/
	/*
	int n;
	cin >> n;

	int* num = new int[2*n];

	loop(i, 2*n)
		num[i] = 0;
	string xname;

	while (getline(cin,  xname))
	{
		istringstream ss(xname) ;

	}

	int ns;
	loop(i, 2*n)
	{
		ns = 0;
		if (!(cin >> xname))
		{
			break;
		}
		num[ns] = ns;
	}

	for (int i = 1; i < 2 * n; i++)
	{
		if (num[i] != i)

		{
			cout << "Oh, my keyboard!";
			return;
		}
}
	cout << "I become the guy.";*/
}


#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define loop(i,n)  for(int i =0;i<n;i++)

void main()
{
	int n;
	cin >> n;
	int aOld, aNew, bOld, bNew;
	bool d = true;

	cin >> aOld >> bOld;
	if (bOld - aOld != 0)
	{
		cout << "rated";
		return;
	}
	for (int i = 1; i < n; i++)
	{
		cin >> aNew >> bNew;
		if (bNew - aNew != 0)
		{
			cout << "rated";
			return;
		}

		if (aNew - aOld >= 0)
			d = false;

	}
	if (d)
		cout << "unrated";
	else
		cout << "maybe";

	/*A. I Wanna Be the Guy*/
	/*
	int n;
	cin >> n;

	int* num = new int[2*n];

	loop(i, 2*n)
		num[i] = 0;
	string xname;

	while (getline(cin,  xname))
	{
		istringstream ss(xname) ;

	}

	int ns;
	loop(i, 2*n)
	{
		ns = 0;
		if (!(cin >> xname))
		{
			break;
		}
		num[ns] = ns;
	}

	for (int i = 1; i < 2 * n; i++)
	{
		if (num[i] != i)

		{
			cout << "Oh, my keyboard!";
			return;
		}
}
	cout << "I become the guy.";*/
}


#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define loop(i,n)  for(int i =0;i<n;i++)

void main()
{
	int n;
	cin >> n;
	int aOld, aNew, bOld, bNew;
	bool d = true;

	cin >> aOld >> bOld;
	if (bOld - aOld != 0)
	{
		cout << "rated";
		return;
	}
	for (int i = 1; i < n; i++)
	{
		cin >> aNew >> bNew;
		if (bNew - aNew != 0)
		{
			cout << "rated";
			return;
		}

		if ((aNew - aOld) >= 0)
			d = false;

		aOld = aNew;
		bOld = bNew;
	}
	if (d)
		cout << "maybe";
	else
		cout << "unrated";

	/*A. I Wanna Be the Guy*/
	/*
	int n;
	cin >> n;

	int* num = new int[2*n];

	loop(i, 2*n)
		num[i] = 0;
	string xname;

	while (getline(cin,  xname))
	{
		istringstream ss(xname) ;

	}

	int ns;
	loop(i, 2*n)
	{
		ns = 0;
		if (!(cin >> xname))
		{
			break;
		}
		num[ns] = ns;
	}

	for (int i = 1; i < 2 * n; i++)
	{
		if (num[i] != i)

		{
			cout << "Oh, my keyboard!";
			return;
		}
}
	cout << "I become the guy.";*/
}


#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define loop(i,n)  for(int i =0;i<n;i++)

void main()
{
	int n;
	cin >> n;
	int aOld, aNew, bOld, bNew;
	bool d = true;

	cin >> aOld >> bOld;
	if (bOld - aOld != 0)
	{
		cout << "rated";
		return;
	}
	for (int i = 1; i < n; i++)
	{
		cin >> aNew >> bNew;
		if (bNew - aNew != 0)
		{
			cout << "rated";
			return;
		}

		if ((aNew - aOld) >= 0)
			d = false;

		aOld = aNew;
		bOld = bNew;
	}
	if (d)
		cout << "unrated";
	else
		cout << "maybe";

	/*A. I Wanna Be the Guy*/
	/*
	int n;
	cin >> n;

	int* num = new int[2*n];

	loop(i, 2*n)
		num[i] = 0;
	string xname;

	while (getline(cin,  xname))
	{
		istringstream ss(xname) ;

	}

	int ns;
	loop(i, 2*n)
	{
		ns = 0;
		if (!(cin >> xname))
		{
			break;
		}
		num[ns] = ns;
	}

	for (int i = 1; i < 2 * n; i++)
	{
		if (num[i] != i)

		{
			cout << "Oh, my keyboard!";
			return;
		}
}
	cout << "I become the guy.";*/
}


#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define loop(i,n)  for(int i =0;i<n;i++)

void main()
{
	int n;
	cin >> n;
	int aOld, aNew, bOld, bNew;
	bool d = true;

	cin >> aOld >> bOld;
	if (bOld - aOld != 0)
	{
		cout << "rated";
		return;
	}
	for (int i = 1; i < n; i++)
	{
		cin >> aNew >> bNew;
		if (bNew - aNew != 0)
		{
			cout << "rated";
			return;
		}

		if (aNew - aOld > 0)
			d = false;

	}
	if (d)
		cout << "unrated";
	else
		cout << "maybe";

	/*A. I Wanna Be the Guy*/
	/*
	int n;
	cin >> n;

	int* num = new int[2*n];

	loop(i, 2*n)
		num[i] = 0;
	string xname;

	while (getline(cin,  xname))
	{
		istringstream ss(xname) ;

	}

	int ns;
	loop(i, 2*n)
	{
		ns = 0;
		if (!(cin >> xname))
		{
			break;
		}
		num[ns] = ns;
	}

	for (int i = 1; i < 2 * n; i++)
	{
		if (num[i] != i)

		{
			cout << "Oh, my keyboard!";
			return;
		}
}
	cout << "I become the guy.";*/
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n, mayb=0;
	cin>>n;
	int *a = new int [n];
	int *b = new int [n];
	for (int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	for (int i=0;i<n;i++)
	{
		if (a[i]!=b[i]) return cout<<"rated"<<endl, 0;

	}
	for (int i=0;i<n-1;i++)
	    if (a[i+1]>a[i])  return cout<<"unrated"<<endl, 0;
	cout<<"maybe"<<endl;
	delete[] a;
	delete[] b;
//	system("pause");
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n, mayb=0;
	cin>>n;
	int *a = new int [n];
	int *b = new int [n];
	for (int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	for (int i=0;i<n;i++)
	{
		if (a[i]!=b[i]) return cout<<"rated"<<endl, 0;
		if (a[i]==b[i] && a[i]>=a[i+1]) mayb++;
	}
	if (mayb==n) cout<<"maybe"<<endl;
	else cout<<"unrated"<<endl;
	delete[] a;
	delete[] b;
	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,j=0;
	cin >> n;
	int*arr = new int[n];
	int*arr1 = new int[n];
	int rated = 0;
	int maybe=1;
	for (int i = 0; i < n ; i++)
		cin >> arr[i]>>arr1[i];
	for (int i = 0; i<n; i++)
	if (arr[i] == arr1[j])
	{
		j++;
		continue;

	}
	else {
		rated = 1;
			break;

	    }

	if (rated == 0)
	{
		for (int i = 0; i<n-1 ; i++)
		if (arr[i] < arr[i + 1])
		{
			maybe = 0;
		}
	}
	if (rated==1)
		cout<<"rated"<<endl;
	else
	{
		if (maybe == 1)
			cout << "maybe" << endl;
		else
			cout << "unrated" << endl;

	}
	}


#include<iostream>
using namespace std;
int main()
{
	int n,j=0;
	cin >> n;
	int*arr = new int[n];
	int*arr1 = new int[n];
	int rated = 0;
	int maybe=1;
	for (int i = 0; i < n ; i++)
		cin >> arr[i]>>arr1[i];
	for (int i = 0; i<n; i++)
	if (arr[i] == arr1[j])
	{
		j++;
		continue;

	}
	else {
		rated = 1;
			break;

	    }

	if (rated == 0)
	{
		for (int i = 0; i<n ; i++)
		if (arr[i] < arr[i + 1])
		{
			maybe = 0;
		}
	}
	if (rated==1)
		cout<<"rated"<<endl;
	else
	{
		if (maybe == 1)
			cout << "maybe" << endl;
		else
			cout << "unrated" << endl;

	}
	}


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int*arr = new int[n*2];

	for (int i = 0; i < n * 2; i++)
		cin >> arr[i];
	for (int i = 0; i<n*2; i+=2)
	for (int j = 0; i<n * 2; j+=2)
	if (arr[i] == arr[j+1])
		continue;
	else {
		cout<<"rated"<<endl;
		exit(0);
	}
	for (int i = 0; i<n * 2; i += 2)
	for (int j = 0; i<n * 2; j += 2)
	if (arr[i] == arr[j])
	{
		cout << "maybe" << endl;
		exit(0);
	}
	cout << "unrated" << endl;
	}


#include<iostream>
using namespace std;
int main()
{
	int n1, m;
	cin >> n1 >> m;
	bool c=false;
	while (n1&&m){
		n1--;
		m--;
		if (c == false)
			c = true;
		else
			c = false;

	}
	if (c)
		puts("Akshat");
	else
		puts("Malvika");
	return 0;

}


#include<iostream>
using namespace std;
int main()
{
	int n,j=0;
	cin >> n;
	int*arr = new int[n];
	int*arr1 = new int[n];
	int rated = 0;
	int maybe=1;
	for (int i = 0; i < n ; i++)
		cin >> arr[i]>>arr1[i];
	for (int i = 0; i<n; i++)
	if (arr[i] == arr1[j])
	{
		continue;
		j++;
	}
	else {
		rated = 1;
			break;

	    }

	if (rated == 0)
	{
		for (int i = 0; i<n ; i++)
		if (arr[i] < arr[i + 1])
		{
			maybe = 0;
		}
	}
	if (rated==1)
		cout<<"rated"<<endl;
	else
	{
		if (maybe == 1)
			cout << "maybe" << endl;
		else
			cout << "unrated" << endl;

	}
	}


#include<iostream>
using namespace std;
int main()
{
	int n,j=0;
	cin >> n;
	int*arr = new int[n];
	int*arr1 = new int[n];
	int rated = 0;
	for (int i = 0; i < n ; i++)
		cin >> arr[i]>>arr1[i];
	for (int i = 0; i<n; i++)
	if (arr[i] == arr1[j])
	{
		continue;
		j++;
	}
	else {
		rated = 1;
			break;

	    }
	if (rated == 1)
	{

		for (int i = 0; i<n - 1; i++)
		if (arr[i] > arr[i + 1])
		{
			cout << "rated" << endl;
			exit(0);
		}
	}
	if (rated == 0)
	{

		j++;
		for (int i = 0; i<n - 1; i++)
		if (arr[i] > arr[i + 1])
		{
			cout << "maybe" << endl;
			exit(0);
		}
	}
	cout << "unrated" << endl;
	}


#include<iostream>
using namespace std;
int main()
{
	int n,j=0;
	cin >> n;
	int*arr = new int[n];
	int*arr1 = new int[n];

	for (int i = 0; i < n ; i++)
		cin >> arr[i]>>arr1[i];
	for (int i = 0; i<n; i++)
	if (arr[i] == arr1[j])
	{
		continue;
		j++;
	}
	else {
		cout<<"rated"<<endl;

		exit(0);
	    }
	for (int i = 0; i<n ; i += 2)
	if (arr[i] > arr[i+1])
	{
		cout << "maybe" << endl;
		exit(0);
	}
	cout << "unrated" << endl;
	}


#include<iostream>
using namespace std;
int main()
{
	int n,j=0;
	cin >> n;
	int*arr = new int[n];
	int*arr1 = new int[n];
	int rated = 0;
	int maybe=1;
	for (int i = 0; i < n ; i++)
		cin >> arr[i]>>arr1[i];
	for (int i = 0; i<n; i++)
	if (arr[i] == arr1[j])
	{
		continue;
		j++;
	}
	else {
		rated = 1;
			break;

	    }

	if (rated == 0)
	{

		for (int i = 0; i<n - 1; i++)
		if (arr[i] > arr[i + 1])
		{
			maybe = 0;
		}
	}
	if (rated==1)
		cout<<"rated"<<endl;
	else if (maybe==1)
			cout<<"maybe"<<endl;
		else
			cout<<"unrated"<<endl;
	}


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int*arr = new int[n*2];

	for (int i = 0; i < n * 2; i++)
		cin >> arr[i];
	for (int i = 0; i<n*2; i+=2)
	for (int j = i; i<n * 2; j+=2)
	if (arr[i] == arr[j+1])
		continue;
	else {
		cout<<"rated"<<endl;
		exit(0);
	    }
	for (int i = 0; i<n * 2; i += 2)
	for (int j = 0; i<n * 2; j += 2)
	if (arr[i] > arr[j])
	{
		cout << "maybe" << endl;
		exit(0);
	}
	cout << "unrated" << endl;
	}


#include<iostream>
using namespace std;
int main()
{
	int n,j=0;
	cin >> n;
	int*arr = new int[n];
	int*arr1 = new int[n];
	int rated = 0;
	for (int i = 0; i < n ; i++)
		cin >> arr[i]>>arr1[i];
	for (int i = 0; i<n; i++)
	if (arr[i] == arr1[j])
	{
		continue;
		j++;
	}
	else {
		rated = 1;
			break;

	    }
	j = 0;
	for (int i = 0; i<n; i++)
	if (arr[i] != arr[j])
	{
		cout << "rated" << endl;
		exit(0);
	}
	else
		j++;
	for (int i = 0; i<n; i ++)
	if (arr[i] > arr[i+1])
	{
		cout << "maybe" << endl;
		exit(0);
	}
	cout << "unrated" << endl;
	}


#include<iostream>
using namespace std;
int main()
{
	int n,j=0;
	cin >> n;
	int*arr = new int[n];
	int*arr1 = new int[n];
	int rated = 0;
	int maybe=1;
	for (int i = 0; i < n ; i++)
		cin >> arr[i]>>arr1[i];
	for (int i = 0; i<n; i++)
	if (arr[i] == arr1[j])
	{
		continue;
		j++;
	}
	else {
		rated = 1;
			break;

	    }

	if (rated == 0)
	{

		for (int i = 0; i<n - 1; i++)
		if (arr[i] > arr[i + 1])
		{
			maybe = 0;
		}
	}
	if (rated==1)
		cout<<"rated"<<endl;
	else
	{
		if (maybe == 1)
			cout << "maybe" << endl;
		else
			cout << "unrated" << endl;

	}
	}


#include<iostream>
using namespace std;
int main()
{
	int n,j=0;
	cin >> n;
	int*arr = new int[n];
	int*arr1 = new int[n];
	int rated = 0;
	int maybe=1;
	for (int i = 0; i < n ; i++)
		cin >> arr[i]>>arr1[i];
	for (int i = 0; i<n; i++)
	if (arr[i] == arr1[j])
	{
		continue;
		j++;
	}
	else {
		rated = 1;
			break;

	    }

	if (rated == 0)
	{

		for (int i = 0; i<n - 1; i++)
		if (arr[i] < arr[i + 1])
		{
			maybe = 0;
		}
	}
	if (rated==1)
		cout<<"rated"<<endl;
	else
	{
		if (maybe == 1)
			cout << "maybe" << endl;
		else
			cout << "unrated" << endl;

	}
	}


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int*arr = new int[n*2];

	for (int i = 0; i < n * 2; i++)
		cin >> arr[i];
	for (int i = 0; i<n*2; i+=2)
	for (int j = 0; i<n * 2; j+=2)
	if (arr[i] == arr[j+1])
		continue;
	else {
		cout<<"rated"<<endl;
		exit(0);
	    }
	for (int i = 0; i<n * 2; i += 2)
	for (int j = 0; i<n * 2; j += 2)
	if (arr[i] > arr[j])
	{
		cout << "maybe" << endl;
		exit(0);
	}
	cout << "unrated" << endl;
	}


#include<iostream>
using namespace std;
int main()
{
	int n,j=0;
	cin >> n;
	int*arr = new int[n];
	int*arr1 = new int[n];
	int rated = 0;
	for (int i = 0; i < n ; i++)
		cin >> arr[i]>>arr1[i];
	for (int i = 0; i<n; i++)
	if (arr[i] == arr1[j])
	{
		continue;
		j++;
	}
	else {
		rated = 1;
			break;

	    }
	j = 0;
	if (rated = 1)
	for (int i = 0; i<n; i++)
	if (arr[i] != arr[j])
	{
		cout << "rated" << endl;
		exit(0);
	}
	else
		j++;
	for (int i = 0; i<n; i ++)
	if (arr[i] > arr[i+1])
	{
		cout << "maybe" << endl;
		exit(0);
	}
	cout << "unrated" << endl;
	}


#include<iostream>
using namespace std;
int main()
{
	int n,j=0;
	cin >> n;
	int*arr = new int[n];
	int*arr1 = new int[n];
	int rated = 0;
	for (int i = 0; i < n ; i++)
		cin >> arr[i]>>arr1[i];
	for (int i = 0; i<n; i++)
	if (arr[i] == arr1[j])
	{
		continue;
		j++;
	}
	else {
		rated = 1;
			break;

	    }
	if (rated = 1)
	for (int i = 0; i<n-1; i++)
	if (arr[i] > arr[i+1])
	{
		cout << "rated" << endl;
		exit(0);
	}
	else
		j++;
	for (int i = 0; i<n-1; i ++)
	if (arr[i] > arr[i+1])
	{
		cout << "maybe" << endl;
		exit(0);
	}
	cout << "unrated" << endl;
	}


#include<iostream>
#include<algorithm>
#include <ctype.h>
#include<string>
#include<queue>
using namespace std;
int main() {
	int n;
	cin>>n;
	int *x=new int [n];
	int *y=new int[n];
	for(int i=0;i<n;i++)
	cin>>x[i]>>y[i];

	for(int i=0;i<n;i++){
	if(x[i]!=y[i]){
	cout<<"rated\n";
	return 0;
	}
	}
	for(int i=1;i<n;i++){
	if(x[i]>y[i-1]){
	cout<<"unrated\n";
	return 0;}
	}
	cout<<"maybe\n";
	return 0;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include "stdlib.h"
#include <stdio.h>
#include <fstream>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;

int main()
{

	int n;
	cin >> n;
	int *x = new int[n];
	int *y = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i]>>y[i];
		if (x[i] - y[i] != 0) {
			cout << "rated";
			return 0;
		}
	}
	for (int i = 1; i < n; i++) {
		if (x[i - 1] - x[i] < 0) {
			cout << "unrated";
			return 0;
		}
	}

	cout << "maybe";
	return 0;
}


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

int main()
{
	int n,count=0;
	cin >> n;
	int * a = new int[n];
	int * b = new int[n];
	cin >> a[0] >> b[0];
	for (int i = 1; i < n; i++)
	{
		cin >> a[i] >> b[i];
		if (a[i-1] != b[i-1])
		{
			cout << "rated";
			return 0;
		}
		else
			if (a[i-1] == b[i-1] &&a[i-1]>=a[i])
				count++;
	}
	if (a[n - 2] == a[n - 1])
		count++;
	if (count == n-1)
		cout << "maybe";
	else
		cout << "unrated";
}


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

int main()
{
	int n, count = 1;
	cin >> n;
	int * a = new int[n];
	int * b = new int[n];
	cin >> a[0] >> b[0];
	for (int i = 1; i < n; i++)
	{
		cin >> a[i] >> b[i];
		if (a[i-1] != b[i-1])
		{
			cout << "rated";
			return 0;
		}
		else
			if (a[i-1] == b[i-1] &&a[i-1]>=a[i])
				count++;
	}
	if (a[n-1]!=b[n-1])
		count--;
	if (count == n)
		cout << "maybe";
	else
		cout << "unrated";
}


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

int main()
{
	int n,count=0;
	cin >> n;
	int * a = new int[n];
	int * b = new int[n];
	cin >> a[0] >> b[0];
	for (int i = 1; i < n; i++)
	{
		cin >> a[i] >> b[i];
		if (a[i-1] != b[i-1])
		{
			cout << "rated";
			return 0;
		}
		else
			if (a[i-1] == b[i-1] &&a[i-1]>=a[i])
				count++;
	}
	if (a[n - 2] == a[n - 1]&&n>2)
		count++;
	if (count == n-1)
		cout << "maybe";
	else
		cout << "unrated";
}


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

int main()
{
	int n, count = 1;
	cin >> n;
	int * a = new int[n];
	int * b = new int[n];
	cin >> a[0] >> b[0];
	for (int i = 1; i < n; i++)
	{
		cin >> a[i] >> b[i];
		if (a[i-1] != b[i-1])
		{
			cout << "rated";
			return 0;
		}
		else
			if (a[i-1] == b[i-1] &&a[i-1]>=a[i])
				count++;
	}

	if (a[n - 1] != b[n - 1])
	{
		cout << "rated";
		return 0;
	}
	if (count == n)
		cout << "maybe";
	else
		cout << "unrated";
}


#pragma comment(linker, "/STACK:216000000")
#include <iostream>
#include <cstdio>
#include <fstream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>
#include <set>
#include <bitset>
#include <sstream>
#include <array>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
const ll MAX = 100000000LL * 100000000LL;
const ll MIN = numeric_limits<ll>::min();
const double PI = 3.14159265358979;
const ll MOD = 1000000007LL;

template<class T>
ostream& operator<<(ostream& out, vector<T>& v) {
	for (int i = 0; i < v.size(); ++i) out << v[i] << " ";
	return out;
}

template<class T>
istream& operator >> (istream& in, vector<T>& v) {
	for (int i = 0; i < v.size(); ++i) in >> v[i];
	return in;
}

template<class L, class R>
istream& operator >> (istream& in, pair<L, R>& p) {
	in >> p.first >> p.second;
	return in;
}

template<class T>
T lexical_cast(string& s) {
	stringstream ss(s);
	T t;
	ss >> t;
	return t;
}

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

ll cdiv(ll a, ll b) {
	return (a % b) ? (a / b + 1) : (a / b);
}

ll inv(ll n, ll mod) {
	ll pow = mod - 2;
	ll ans = 1;
	ll cur = n;
	while (pow > 0) {
		if (pow & 1) {
			ans *= cur;
			ans %= mod;
		}
		pow /= 2;
		cur *= cur;
		cur %= mod;
	}
	return ans;
}

template<class Cont> void sort(Cont& c) { sort(begin(c), end(c)); }
template<class Cont> void reverse(Cont& c) { reverse(begin(c), end(c)); }

/* ------------------------------------------------
------------------------------------------------- */

int main() {
	ios_base::sync_with_stdio(false);
#ifdef DEBUG
	ifstream cin{ "input.txt" };
	ofstream cout{ "output.txt" };
#endif
	int n;
	cin >> n;
	vector<pair<int, int>> a(n);
	cin >> a;
	for (int i = 0; i < n; ++i) {
		if (a[i].first != a[i].second) {
			cout << "rated";
			return 0;
		}
	}
	for (int i = 1; i < n; ++i) {
		if (a[i].first > a[i - 1].first) {
			cout << "unrated";
			return 0;
		}
	}
	cout << "maybe";
}


#pragma comment(linker, "/STACK:216000000")
#include <iostream>
#include <cstdio>
#include <fstream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>
#include <set>
#include <bitset>
#include <sstream>
#include <array>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
const ll MAX = 100000000LL * 100000000LL;
const ll MIN = numeric_limits<ll>::min();
const double PI = 3.14159265358979;
const ll MOD = 1000000007LL;

template<class T>
ostream& operator<<(ostream& out, vector<T>& v) {
	for (int i = 0; i < v.size(); ++i) out << v[i] << " ";
	return out;
}

template<class T>
istream& operator >> (istream& in, vector<T>& v) {
	for (int i = 0; i < v.size(); ++i) in >> v[i];
	return in;
}

template<class L, class R>
istream& operator >> (istream& in, pair<L, R>& p) {
	in >> p.first >> p.second;
	return in;
}

template<class T>
T lexical_cast(string& s) {
	stringstream ss(s);
	T t;
	ss >> t;
	return t;
}

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

ll cdiv(ll a, ll b) {
	return (a % b) ? (a / b + 1) : (a / b);
}

ll inv(ll n, ll mod) {
	ll pow = mod - 2;
	ll ans = 1;
	ll cur = n;
	while (pow > 0) {
		if (pow & 1) {
			ans *= cur;
			ans %= mod;
		}
		pow /= 2;
		cur *= cur;
		cur %= mod;
	}
	return ans;
}

template<class Cont> void sort(Cont& c) { sort(begin(c), end(c)); }
template<class Cont> void reverse(Cont& c) { reverse(begin(c), end(c)); }

/* ------------------------------------------------
------------------------------------------------- */

int main() {
	ios_base::sync_with_stdio(false);
#ifdef DEBUG
	ifstream cin{ "input.txt" };
	ofstream cout{ "output.txt" };
#endif
	int n;
	cin >> n;
	vector<pair<int, int>> a(n);
	cin >> a;
	for (int i = 0; i < n; ++i) {
		if (a[i].first != a[i].second) {
			cout << "rated";
			return 0;
		}
	}
	for (int i = 1; i < n; ++i) {
		if (a[i].first > a[i - 1].first) {
			cout << "unrated";
			return 0;
		}
	}
	for (int i = 1; i < n; ++i) {
		if (a[i].first == a[i - 1].first) {
			cout << "maybe";
			return 0;
		}
	}
	cout << "unrated";
}


#include <iostream>

using namespace std;
int main()
{
    int n;
    int a, b;
    int temp=9999;
    bool tempy = false;
    cin >> n;
    for (int i=0; i<n; i++)
    {
        cin >> a >> b;
        if (a != b)
        {
            cout << "rated";
            return 0;
        }
        if (a <= temp) temp = a;
        else if (tempy == false) tempy = true;
    }
    if (tempy == true) cout << "unrated";
    else cout <<"maybe";
}


#include <iostream>

using namespace std;
int main()
{
    int n;
    int a, b;
    int temp=9999;
    bool tempy = false;
    cin >> n;
    for (int i=0; i<n; i++)
    {
        cin >> a >> b;
        if (a != b)
        {
            cout << "rated";
            return 0;
        }
        if (a <= temp) temp = a;
        else { tempy = true; break;}
    }
    if (tempy == true) cout << "unrated";
    else cout <<"maybe";
}


#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int i,n,j,c=0,c2=0,a[1010],b[1010],d[1010];
    cin>>n;
    for(i=0;i<n;i++)
    {
    cin>>a[i]>>b[i];
    d[i]=b[i];
    }
    for(i=0;i<n;i++)
     {
        if(a[i]==b[i])
        c++;
     }
    sort(d,d+n);
    for(i=n-1,j=0;i>=0,j<n;i--,j++)
    {

            if(d[i]==b[j])
            c2++;

    }
    if(c!=n)
    cout<<"rated";
    else if(c==n&&c2==n)
    cout<<"maybe";
    else
    {
        cout<<"unrated";
    }
    return 0;

}


#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int i,n,j,c=0,c2=0,a[1010],b[1010],d[1010];
    cin>>n;
    for(i=0;i<n;i++)
    {
    cin>>a[i]>>b[i];
    d[i]=b[i];
    }
    for(i=0;i<n;i++)
     {
        if(a[i]==b[i])
        c++;
     }
    sort(d,d+n);
    for(i=n-1,j=0;i>=0,j<n;i--,j++)
    {

            if(d[i]==b[j])
            c2++;

    }
    if(c!=n)
    cout<<"rated";
    else if(c==n&&c2==n)
    cout<<"may be";
    else
    {
        cout<<"underated";
    }
    return 0;

}


#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int i,n,j,c=0,c2=0,a[1010],b[1010],d[1010];
    cin>>n;
    for(i=0;i<n;i++)
    {
    cin>>a[i]>>b[i];
    d[i]=b[i];
    }
    for(i=0;i<n;i++)
     {
        if(a[i]==b[i])
        c++;
     }
    sort(d,d+n);
    for(i=n-1,j=0;i>=0,j<n;i--,j++)
    {

            if(d[i]==b[j])
            c2++;

    }
    if(c!=n)
    cout<<"rated";
    else if(c==n&&c2==n)
    cout<<"may be";
    else
    {
        cout<<"unrated";
    }
    return 0;

}


#include<fstream>
#include<iostream>
#include<math.h>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<array>
#include<assert.h>
#include<set>
#include<map>
using namespace std;

int main()
{
int persons=0 ;
cin >> persons ;
int a =0;
int b =0;
cin >> a >> b ;
int temp=b ;
int count_1=0 ,count_2=0 ;
for (int i=0;i<persons-1;i++)
{
    if(a!=b){count_1++;}
    cin >> a >> b ;
    if(a!=b){count_1++;}
    if (b>temp){count_2++;}
    temp=b;
}
if(count_1>1){cout << "rated"<<endl;}
else if(count_2>1){cout << "unrated"<<endl;}
else{cout << "maybe"<<endl;}

}


#include<fstream>
#include<iostream>
#include<math.h>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<array>
#include<assert.h>
#include<set>
#include<map>
using namespace std;

int main()
{
int persons=0 ;
cin >> persons ;
int a =0;
int b =0;
cin >> a >> b ;
int temp=b ;
int count_1=0 ,count_2=0 ;

for (int i=0;i<persons-1;i++)
{
    if(a!=b){count_1++;}
    cin >> a >> b ;
    if(a!=b){count_1++;}
    if (b>temp){count_2++;}
    temp=b;
}
if(count_1!=0){cout << "rated"<<endl;}
else if(count_2!=0){cout << "unrated"<<endl;}
else{cout << "maybe"<<endl;}

return 0 ;
}


#include<iostream>
using namespace std;

int n;
int a[1001], b[1001];

int main()
{
		cin >> n;
		int flag = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i] >> b[i];
			if (a[i] != b[i]) flag = 1;
		}
		for (int i = 1; i < n; i++)
		{
			if (!flag && a[i] > a[i - 1])
				flag = 2;
		}
		if (!flag) cout << "maybe" << endl;
		else if (flag == 1) cout << "rated" << endl;
		else cout << "unrated" << endl;
		return 0;
}


//
//  main.cpp
//  is it rated
//
//  Created by Максим Зиновьев on 07.05.17.
//  Copyright © 2017 Максим Зиновьев. All rights reserved.
//

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int n, u;
    vector<int> res;
    string ans = "maybe";

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> u;
        res.push_back(u);
    }

    for (int i = 0; i < n - 1; i+=2)
    {
        if(res[i] < res[i+2])
        {
            ans = "unrated";
            break;
        }
    }

    for (int i = 0; i < n; i+=2)
    {
        if(res[i] != res[i+1])
        {
            ans = "rated";
            break;
        }
    }

    cout << endl << ans;

    return 0;
}


//
//  main.cpp
//  is it rated
//
//  Created by Максим Зиновьев on 07.05.17.
//  Copyright © 2017 Максим Зиновьев. All rights reserved.
//

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int n, u;
    vector<int> res;
    string ans = "maybe";

    cin >> n;

    for (int i = 0; i < n*2; i++)
    {
        cin >> u;
        res.push_back(u);
    }

    for (int i = 0; i < n - 1; i+=2)
    {
        if(res[i] < res[i+2])
        {
            ans = "unrated";
            break;
        }
    }

    for (int i = 0; i < n; i+=2)
    {
        if(res[i] != res[i+1])
        {
            ans = "rated";
            break;
        }
    }

    cout << ans;

    return 0;
}


//
//  main.cpp
//  is it rated
//
//  Created by Максим Зиновьев on 07.05.17.
//  Copyright © 2017 Максим Зиновьев. All rights reserved.
//

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int n, u;
    vector<int> res;
    string ans = "maybe";

    cin >> n;

    for (int i = 0; i < n*2; i++)
    {
        cin >> u;
        res.push_back(u);
    }

    for (int i = 0; i < n * 2 - 2; i+=2)
    {
        if(res[i] < res[i+2])
        {
            ans = "unrated";
            break;
        }
    }

    for (int i = 0; i < n * 2 - 1; i+=2)
    {
        if(res[i] != res[i+1])
        {
            ans = "rated";
            break;
        }
    }

    cout << ans;

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <ctime>
#include <cstdlib>
#include <ctype.h>
#include <math.h>
#include <fstream>

using namespace std;

int n;
vector<pair<int, int>> mp;

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

	cin >> n;
	mp.resize(n);

	for (int i = 0; i < n; ++i)
	{
		int a, b;
		cin >> a >> b;

		if (a != b)
		{
			cout << "rated" << endl;
			return 0;
		}

		mp[i] = make_pair(a, b);
	}

	for (int i = 1; i < n; ++i)
	{
		if (mp[i].second > mp[i - 1].second)
		{
			cout << "unrated" << endl;
			return 0;
		}
	}

	cout << "maybe" << endl;

	return 0;
}


#include <iostream>
#include <set>
using namespace std;
set<int> s[1005];
int main()
{
    int n;
    int flag;
    int sign;
    while(cin>>n)
    {
        flag=0;
        sign=0;
        for(int i=0; i<n; i++)
        {
            int x,y;
            cin>>x>>y;
            s[i].insert(x);
            s[i].insert(y);
        }

        for(int i=0; i<n; i++)
        {
            if(s[i].size()==2)
            {
                cout<<"rated"<<endl;
                flag=1;
                break;
            }
        }
        if(flag!=1)
        {
            for(int i=0; i<n; i++)
            {
                if(s[i+1]>s[i])
                {
                    cout<<"unrated"<<endl;
                    sign=1;
                    break;
                }
            }
        }
        if(flag==0&&sign==0)
            cout<<"maybe"<<endl;
        for(int i=0; i<n; i++)
            s[i].clear();
    }
    return 0;
}


#include <vector>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	vector<int> arr1;
	vector<int> arr2;
	vector<int> arr1S;
	vector<int> arr2S;

	int n;
	cin >> n;

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

		arr1.push_back(x);

		int y;
		cin >> y;

		arr2.push_back(y);
	}

	arr1S = arr1;
	sort(arr1S.begin(), arr1S.end(), greater<int>());

	arr2S = arr2;
	sort(arr2S.begin(), arr2S.end(), greater<int>());

	for (int i = 0; i < n; i++)
	{
		if (arr1[i] != arr2[i])
		{
			cout << "rated" << endl;
			return 0;
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (arr1[i] != arr1S[i])
		{
			cout << "unrated" << endl;
			return 0;
		}
	}

	cout << "maybe" << endl;

	return 0;
}


#include<iostream>
using namespace std;
void main()
{
	int n,a[1000],b[1000],rated=0,max=4127,unrated=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
		if(a[i]!=b[i])
			rated++;

	}
	if(rated==0)

		{for(int u=0;u<n;u++)
		{
			if(max>=a[u])
				max=a[u];
			else
				unrated++;

		}
	if(unrated==0)
		cout<<"maybe"<<endl;
	else
		cout<<"unrated"<<endl;}

	else
	cout<<"rated"<<endl;

}


#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main()
{
    bool flag1=0,flag2=0;
    int n=0,a=0,b=0;
    vector<int>vec;
    multiset<int>st;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        if(a!=b)
            flag1=1;
        vec.push_back(a);
        st.insert(a);
    }
     multiset<int>::iterator it=st.end();
     it--;
     for(int i=0;i<vec.size();i++)
     {
         if(vec[i]!=*it)
            flag2=1;
         it--;
     }

    if(flag1==1)
        cout<<"rated"<<endl;
    else if(flag2==1)
        cout<<"unrated"<<endl;
    else
        cout<<"maybe"<<endl;

    return 0;
}


#include <iostream>
using namespace std;

int main(){

   int n;
   cin >> n;
   int* arr = new int[n];
	int* arr2 = new int[n];
   for (int i =0; i < n ; i++){

	   cin >>  arr[i] >> arr2[i];
	   if (arr[i] != arr2[i])
	   {
		   cout << "rated" << endl;
		   return 0;
	   }

   }
    for (int i =0; i < n ; i++)
	{
   if(arr[i] > arr[i-1] || arr2[i] > arr2[i-1])
		{
		   cout << "unrated" << endl;
		   return 0;
	   }
	}
   cout << "maybe" << endl;
   return 0;
}


#include <iostream>
using namespace std;

int main(){

   int n;
   cin >> n;
   int* arr = new int[n];
	int* arr2 = new int[n];
   for (int i =0; i < n ; i++){

	   cin >>  arr[i] >> arr2[i];
	   if (arr[i] != arr2[i])
	   {
		   cout << "rated" << endl;
		   return 0;
	   }

   }
    for (int i =0; i < n ; i++)
	{
   if(arr[i] > arr[i-1] )
		{
		   cout << "unrated" << endl;
		   return 0;
	   }
	}
   cout << "maybe" << endl;
   return 0;
}


#include <iostream>
using namespace std;

int main(){

   int n;
   cin >> n;
   int* arr = new int[n];
	int* arr2 = new int[n];
   for (int i =0; i < n ; i++){

	   cin >>  arr[i] >> arr2[i];
   }
    for (int i =0; i < n ; i++){
	   if (arr[i] != arr2[i])
	   {
		   cout << "rated" << endl;
		   return 0;
	   }

   }
    for (int i =0; i < n ; i++)
	{
   if(arr[i] > arr[i-1] )
		{
		   cout << "unrated" << endl;
		   return 0;
	   }
	}
   cout << "maybe" << endl;
   return 0;
}


#include <iostream>
using namespace std;

int main(){

   int n;
   cin >> n;
   int* arr = new int[n];
	int* arr2 = new int[n];
   for (int i =0; i < n ; i++)
   {

	   cin >>  arr[i] >> arr2[i];

	{
	   if (arr[i] != arr2[i])
	   {
		   cout << "rated" << endl;
		   return 0;
	   }

   }
    for (int i =0; i < n ; i++)
	{
		if(arr[i] > arr[i-1] )
		{
			cout << "unrated" << endl;
			return 0;
		}
	}
   cout << "maybe" << endl;

   }
return 0;
}


#include <iostream>
using namespace std;

int main(){

   int n,  arr[1000],  arr2[1000];
   cin >> n;

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

	   cin >>  arr[i] >> arr2[i];
   }

	for (int i =0; i < n ; i++)
   {
	   if (arr[i] != arr2[i])
	   {
		   cout << "rated" << endl;
		   return 0;
	   }

   }
    for (int i =1; i < n ; i++)
	{
		if(arr[i] > arr[i-1] )
		{
			cout << "unrated" << endl;
			return 0;
		}
	}
   cout << "maybe" << endl;

return 0;
}


#include <iostream>
using namespace std;

int main(){

   int n,  arr[1000],  arr2[1000];
   cin >> n;

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

	   cin >>  arr[i] >> arr2[i];
   }

	for (int i =0; i < n ; i++)
   {
	   if (arr[i] != arr2[i])
	   {
		   cout << "rated" << endl;
		   return 0;
	   }

   }
    for (int i =0; i < n ; i++)
	{
		if(arr[i] > arr[i-1] )
		{
			cout << "unrated" << endl;
			return 0;
		}
	}
   cout << "maybe" << endl;

return 0;
}


#include <iostream>
using namespace std;

int main(){

   int n;
   cin >> n;
   int* arr = new int[n];
	int* arr2 = new int[n];
   for (int i =0; i < n ; i++){

	   cin >>  arr[i] >> arr2[i];
	   if (arr[i] != arr2[i])
	   {
		   cout << "rated" << endl;
		   return 0;
	   }
	   if(arr[i] > arr[i-1] || arr2[i] > arr2[i-1])
		{
		   cout << "unrated" << endl;
		   return 0;
	   }

   }
   cout << "maybe" << endl;
   return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
	int n, n1, n2,a,b;
	cin >> n;
	b = 1;
	vector <int> v;
	for (int i = 0; i < n; i++) {
		cin >> n1 >> n2;
		v.push_back(n1);
		v.push_back(n2);
	}
	for (int i = 0; i < 2 * n; i=i+2) {
		if (v[i] != v[i + 1]) {
			cout << "rated";
			return 0;
		}
	}
	for (int j = 0; j < 2 * n-2; j=j+2) {
		if (v[j] >= v[j + 2]) {
			b++;
		}
	}
	if (b == n) {
		cout << "maybe";
	}
	else {
		cout << "unrated";
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
	int n, n1, n2,a,b;
	cin >> n;
	b = 0;
	vector <int> v;
	for (int i = 0; i < n; i++) {
		cin >> n1 >> n2;
		v.push_back(n1);
		v.push_back(n2);
	}
	for (int i = 0; i < 2 * n; i=i+2) {
		if (v[i] != v[i + 1]) {
			cout << "rated";
			return 0;
		}
	}
	for (int j = 0; j < 2 * n-2; j=j+2) {
		if (v[j] >= v[j + 2]) {
			b++;
		}
	}
	if (b == n) {
		cout << "maybe";
	}
	else {
		cout << "unrated";
	}
	return 0;
}


#include <iostream>
#include"cmath"
using namespace std;

int main()
{
    int m1,m2,m3,m4,n;
    cin>>n;
    int test=1;
    cin>>m1>>m2;
    for(int i=1;i<n;i++){
        m3=m1;
        m4=m2;
        cin>>m1>>m2;
        if(m1!=m2||m4!=m3){
            test=2;
            break;
        }
        else if(m3<m1){
            test=3;
            break;
        }
    }
    if (test==1)
        cout<<"maybe";
    if(test==2)
        cout<<"rated";
    if(test==3)
        cout<<"unrated";
}


#include <iostream>
#include"cmath"
using namespace std;

int main()
{
    int m1,m2,m3,m4,n;
    cin>>n;
    int test=1;
    cin>>m1>>m2;
    for(int i=1;i<n;i++){
        m3=m1;
        m4=m2;
        cin>>m1>>m2;
        if(m1!=m2||m4!=m3){
            test=2;
            break;
        }
        else if(m3<m1){
            test=3;
            continue;
        }
    }
    if (test==1)
        cout<<"maybe";
    if(test==2)
        cout<<"rated";
    if(test==3)
        cout<<"unrated";
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
  int k, o, n;
  int prev = 5000;
  cin >> k;
  bool rated = false;
  bool unrated = false;
  for (int i = 0; i < k; i++) {
    cin >> o >> n;
	if (o != n)
		rated = true;
	if (o > prev)
		unrated = true;
	prev = o;
  }
  cout << (rated ? "rated" : (unrated ? "unrated" : "maybe")) << endl;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
  int k, o, n;
  int prev = 5000;
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> o >> n;
	if (o != n) {
		cout << "rated" << endl;
		return 0;
	}
	if (o > prev) {
		cout << "unrated" << endl;
		return 0;
	}
	prev = o;
  }
  cout << "maybe" << endl;
}


#include<iostream>
using namespace std;
int main()
{
	int x[1005], y[1005], n, r = 0, q = 0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> x[i] >> y[i];

	}
	for (int i = 0; i < n; i++){
		if (x[i] != y[i])
			r++;
		else if (x[i + 1]>x[i] || y[i + 1]>y[i])
			q++;
	}
	if (r > 0)
		cout << "rated" << endl;
	else if (q>0)
		cout << "unrated" << endl;
	else
		cout << "maybe" << endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int x[1005], y[1005], n, r = 0, q = 0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> x[i] >> y[i];
	}
	for (int i = 0; i < n; i++){
		if (x[i] != y[i])
			r++;
		else if (x[i + 1]>x[i] || y[i + 1]>y[i])
			q++;
	}
	if (r > 0)
		cout << "rated" << endl;
	else if (q>0)
		cout << "unrated" << endl;
	else
		cout << "maybe" << endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	vector<int> b;
	int n, *a , x;
	cin >> n;
	a = new int[n+2];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		cin >> x;
		b.push_back(x);

	}
	for (int i = 0; i < n; i++)
		if (a[i] != b[i])
		{
			cout << "rated" << endl;
			return 0;
		}

		sort(b.begin(), b.end());
		for (int i = 0; i < n; i++)
			if (a[i] != b[n-i-1])
			{
				cout << "unrated" << endl;
				return 0;
			}

	cout << "maybe" << endl;
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int after2 = 0,israted=0,isunrated=0;
	for (int i = 0; i < n; i++)
	{
		int before1, after1;
		cin >> before1 >> after1;
		if (before1 != after1)
			israted = 1;

		if ((after2 != 0)&&(after1 > after2))
				isunrated = 1;

		after2 = after1;
	}
	if (israted)
		cout << "rated" << endl;
	else if (isunrated)
		cout << "unrated" << endl;
	else
		cout << "maybe" << endl;
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int after2 = 0;
	for (int i = 0; i < n; i++)
	{
		int before1, after1;
		cin >> before1 >> after1;
		if (before1 != after1)
		{
			cout << "rated" << endl;
			return 0;
		}
		if (after2 != 0)
		{
			if (after1 > after2)
			{
				cout << "unrated" << endl;
				return 0;
			}
			after2 = after1;
		}
		else
			after2 = after1;
	}
	cout << "maybe" << endl;
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
   int x,min,c=0;
   cin>>x;
   int *y=new int [x];
   int *q=new int [x];
   for (int i=0;i<x;i++)
   {
	   cin>>y[i]>>q[i];
   }
    for (int i=0;i<x;i++)
	{
		if (y[i]!=q[i])
		{
			cout<<"rated\n";
			c=1;
			break;
		}
	}
	min=0;
	for (int i=1;i<x;i++)
	{
		if (y[min]>y[i])
			min=i;
	}
	if (min==x-1 && c==0)
	{
		cout<<"maybe\n";

	}
	else if (min!=x-1 && c==0)
		cout<<"unrated\n";

    return 0;
}


#include <iostream>
using namespace std;

int main()
{
   int x,min,c=0,z=0;
   cin>>x;
   int *y=new int [x];
   int *q=new int [x];
   for (int i=0;i<x;i++)
   {
       cin>>y[i]>>q[i];
   }
    for (int i=0;i<x;i++)
    {
        if (y[i]!=q[i])
        {
            cout<<"rated\n";
            z=1;
            break;
        }
    }
    min=0;
    for (int i=1;i<x;i++)
    {
        if (y[i]>y[i-1])
        {
            c++;
        }
    }
    if (c==0 && z==0)
    {
        cout<<"maybe\n";
    }
    else if (c!=0 && z==0)
    {
        cout<<"unrated\n";
    }

    return 0;
}