var s:string(999);i,n:word;begin repeat readln(s);val(copy(s,length(s)-2),n,i);writeln((ord(s[pos(^`,s)-1])-48)pow(3and(n+3)+1)mod 10)until 0>0end.