/**************************************************************
Problem: 2460
User: idy002
Language: C++
Result: Accepted
Time:68 ms
Memory:832 kb
****************************************************************/ #include <cstdio>
#include <algorithm>
#define N 1010
using namespace std; typedef unsigned long long dnt; struct Pair {
dnt v;
int w;
void read() { scanf( "%llu%d", &v, &w ); }
bool operator<( const Pair &p ) const { return w<p.w; }
}; int n;
Pair prs[N];
dnt a[N], b[N]; int tot; bool ok() {
for( int i=; i<tot; i++ )
b[i] = a[i];
for( int i=,j=; i>= && j<tot; i-- ) {
for( int k=j; k<tot; k++ )
if( (b[k]>>i) & ) {
swap( b[k], b[j] );
break;
}
if( (b[j]>>i)== ) {
for( int k=j+; k<tot; k++ )
if( (b[k]>>i) & ) {
b[k] ^= b[j];
if( b[k]== ) return false;
}
j++;
}
}
return true;
}
int main() {
scanf( "%d", &n );
for( int i=; i<=n; i++ )
prs[i].read();
sort( prs+, prs++n );
int ans = ;
for( int i=n; i>=; i-- ) {
a[tot++] = prs[i].v;
if( ok() ) {
ans += prs[i].w;
} else {
tot--;
}
}
printf( "%d\n", ans );
}