#include<iostream>
#include<string>

using namespace std;

int main(){
	int A,B,C,s,t,u;
	string x;
	A=1,B=2,C=3;
	while(cin>>x){
		if((x==(A,B))||(x==(B,A))){
			s=A;
			A=B;
			B=z;
		}else if((x==(C,B))||(x==(B,C))){
			t=B;
			B=C;
			C=t;
		}else if((x==(A,C))||(x==(C,A))){
			u=C;
			C=A;
			A=u;
		}
	}
	if(A==1){A=A;
	}else if(A==2){A=B;
	}else if(A==3){A=C;
	};
	cout << A << endl;
}
