#include<bits/stdc++.h>
#define LL long long
#define N 3000010
using namespace std;
vector<vector<LL>> num(N);
int main(){
std::ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,q;
cin>>n>>q;
for(int i = 0;i<n;i++){
int s;
cin>>s;
for(int j = 0;j<s;j++){
LL x;
cin>>x;
num[i].push_back(x);
}
}
LL ans = 0;
while(q--){
int x,y;
cin>>x>>y;
ans^=num[x-1][y-1];
}
cout<<ans<<endl;
return 0;
}