a,b=$<.map &:to_i c=b%4 p case d=a%10 when 2;[2,4,8,6][c] when 3;[3,9,7,1][c] when 4;[4,6,4,6][c] when 7;[7,9,3,1][c] when 8;[8,4,2,6][c] when 9;[9,1,9,1][c] else d end