#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdio>
using namespace std;
typedef long long LL;
const int N = 64;
struct Node
{
int val;
LL id;
bool operator<(const Node &t) const
{
return val < t.val;
}
}a[1010];
int d[N];
int n;
bool insert(LL x)
{
for (int i = 63; i >= 0; i -- )
{
if (x >> i & 1)
{
if (d[i]) x ^= d[i];
else
{
d[i] = x;
return true;
}
}
}
return false;
}
int main()
{
int res = 0;
scanf("%d", &n);
for (int i = 0; i < n; i ++ )
{
cin >> a[i].id >> a[i].val;
}
sort(a, a + n);
reverse(a, a + n);
for (int i = 0; i < n; i ++ )
{
if (insert(a[i].id)) res += a[i].val;
}
cout << res << endl;
return 0;
}