memo = [0, 0] memo[0], memo[1], N = map(int, raw_input().split()) memo.append(memo[0], memo[1]) print memo[N%3]