#!/usr/bin/env python3
import sys

k = int(input())
ans = 1<<30
for _ in range(k):
    (y, c1, c2) = map(int, input().split())
    yy = y+1
    while (yy-y) % c1 != 0 or (yy-y) % c2 != 0:
        yy += 1
    ans = min(ans, yy)

assert ans >= 2022

print(ans)

sys.exit(42)
