from collections import defaultdict import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) N = int(input()) card = defaultdict(int) for _ in range(N): K, L, D = map(int, input().split()) two = pow(2, D) for _ in range(K): card[L] ^= 1 L += two ans = -1 for k, v in card.items(): if v: ans = k print(ans)