q = int(input()) a, b = map(int, input().split()) print(b * (b + 1) // 2 % 17)