It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor.

Doctors have a strange working schedule. The doctor i goes to work on the s_{i}-th day and works every d_{i} day. So, he works on days s_{i}, s_{i} + d_{i}, s_{i} + 2d_{i}, ....

The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors?


-----Input-----

First line contains an integer n — number of doctors (1 ≤ n ≤ 1000). 

Next n lines contain two numbers s_{i} and d_{i} (1 ≤ s_{i}, d_{i} ≤ 1000).


-----Output-----

Output a single integer — the minimum day at which Borya can visit the last doctor.


-----Examples-----
Input
3
2 2
1 2
2 2

Output
4

Input
2
10 1
6 5

Output
11



-----Note-----

In the first sample case, Borya can visit all doctors on days 2, 3 and 4.

In the second sample case, Borya can visit all doctors on days 10 and 11.

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
n = int(input())
ans = 0
for i in range(n):
	(s, d) = [int(i) for i in input().split()]
	if s > ans:
		ans = s
	else:
		ans = s + ((ans - s) // d + 1) * d
print(ans)


n = int(input())
ans = 0
for i in range(n):
	(s, d) = list(map(int, input().split()))
	visit = s
	while visit <= ans:
		visit += d
	ans = visit
print(ans)


import math
nn = int(input())
cur_day = 0
for i in range(nn):
	(x, y) = map(int, input().split())
	cur_day = x + math.ceil(max(cur_day - x, 0) / y) * y
	cur_day += 1
print(cur_day - 1)


import queue

def readTuple():
	return input().split()

def readInts():
	return tuple(map(int, readTuple()))

def solve():
	(n,) = readInts()
	time = 0
	for _ in range(n):
		(u, v) = readInts()
		if u > time:
			time = u
			continue
		time -= u
		time = (time // v + 1) * v + u
	print(time)
solve()


n = int(input())
for i in range(n):
	(si, di) = list(map(int, input().split()))
	if i == 0:
		sum = si
	elif si <= sum:
		if si + di <= sum:
			nd = (sum - (si + di)) // di + 1
			sum = si + di + nd * di
		else:
			sum = si + di
	else:
		sum = si
print(sum)


n = int(input())
k = 0
for i in range(n):
	(s, d) = list(map(int, input().split()))
	p = k - s
	k = s + d * (p // d + 1 * (k - s % d != 0 or p == 0)) * (p >= 0)
print(k)


n = int(input())
l = []
for i in range(n):
	tp = list(map(int, input().split()))
	l.append(tp)
s1 = 0
for i in range(n):
	if i == 0:
		s1 = l[i][0]
	else:
		j1 = 0
		while True:
			t1 = l[i][0] + j1 * l[i][1]
			if t1 > s1:
				s1 = t1
				break
			j1 += 1
print(s1)


x = int(input())
day_num = super_days = 1
itters = 0
doctors = [[*map(int, input().split())] for _ in range(x)]
while 1:
	itters += 1
	if day_num <= doctors[0][0]:
		day_num = doctors[0][0]
	elif day_num < doctors[0][0] + doctors[0][1]:
		day_num += doctors[0][0] + doctors[0][1] - day_num
	if abs(day_num - doctors[0][0]) % doctors[0][1] == 0:
		doctors = doctors[1:]
	day_num += 1
	if not doctors:
		break
print(day_num - 1)


from math import *
n = int(input())
(a, b) = map(int, input().split())
ans = a
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	if a < ans:
		x = ceil((ans - a) / b)
		ans = a + b * ((ans - a) // b + 1)
	elif a == ans:
		ans = a + b
	else:
		ans = a
print(ans // 1)


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
n = int(input())
tempp = n - 1
lastday = 0
while n:
	n -= 1
	(s, d) = map(int, input().split())
	if n == tempp:
		lastday = s
	elif s > lastday:
		lastday = s
	elif s == lastday:
		lastday = s + d
	else:
		nn = lastday + 1 - s
		if nn % d == 0:
			temp = nn // d
			lastday = s + temp * d
		else:
			temp = nn // d
			temp += 1
			lastday = s + temp * d
print(lastday)


n = int(input())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
curr = 0
for i in range(n):
	if curr < a[i][0]:
		curr = a[i][0]
	else:
		curr = a[i][0] + ((curr - a[i][0]) // a[i][1] + 1) * a[i][1]
print(curr)


n = int(input())
p = []
for i in range(n):
	temp = input().split()
	p.append([int(i) for i in temp])
day = 1
while p != []:
	s = p[0][0]
	d = p[0][1]
	if day >= s and (day - s) % d == 0:
		p.remove(p[0])
	day += 1
print(day - 1)


def main():
	r = 0
	for _ in range(int(input())):
		(s, d) = map(int, input().split())
		r = s + (max(r + 1, s) + d - s - 1) // d * d
	print(r)
main()


def solve():
	N = int(input())
	(a, b) = map(int, input().split())
	day = a
	for (a, b) in (map(int, input().split()) for _ in [0] * (N - 1)):
		if day < a:
			day = a
		else:
			diff = b - (day - a) % b
			day = day + diff if diff > 0 else day + b
	print(day)
solve()


n = int(input())
cur = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if cur < s:
		cur = s
		continue
	if (cur - s) % d == 0:
		cur += d
	else:
		cur += d - (cur - s) % d
print(cur)


N = int(input())
day = 0
for item in range(N):
	(Si, Di) = map(int, input().split())
	if Si > day:
		day = Si
	else:
		day = ((day - Si) // Di + 1) * Di + Si
print(day)


def main():
	n = int(input())
	t = -1
	for i in range(n):
		(si, di) = map(int, input().split())
		if t < si:
			t = si
		else:
			t = ((t - si) // di + 1) * di + si
	print(t)
main()


import sys

def dia(doctors):
	last_day = 0
	for (s, d) in doctors:
		last_day = s + max(0, d * int((last_day - s) / d + 1))
	return last_day
d = None
for i in range(int(input())):
	if d == None:
		d = []
	a = input().split(' ')
	d.append((int(a[0]), int(a[1])))
sys.stdout.write(str(dia(d)))


from math import ceil
read = lambda : tuple(map(int, input().split()))
n = read()[0]
ds = [read() for i in range(n)]
i = 0
for d in range(1, 1000010):
	(dv, kv) = ds[i]
	if d >= dv and (d - dv) % kv == 0:
		i += 1
	if i == n:
		break
print(d)


n = int(input())
b = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if b < s:
		b = s
	else:
		while b >= s:
			s += d
		b = s
print(b)


count = 0
for _ in range(int(input())):
	(s, d) = map(int, input().split())
	if count == 0:
		count += s
	elif s > count:
		count = s
	elif (count - s) % d == 0:
		count += d
	else:
		count = s + ((count - s) // d + 1) * d
print(count)


n = int(input())
day = 0
for i in range(n):
	(s, d) = input().strip().split()
	s = int(s)
	d = int(d)
	if i == 0:
		day = s
	elif s > day:
		day = s
	else:
		day = s + (1 + (day - s) // d) * d
print(day)


n = int(input())
cur = 0
for i in range(n):
	(s, d) = map(int, input().split())
	q = max(0, cur - s + d) // d
	cur = q * d + s
print(cur)


n = int(input())
days = 0
for i in range(n):
	(s, d) = list(map(int, input().split()))
	diff = s - days
	if i > 0 and diff <= 0:
		x = abs(diff) // d + 1
		s += x * d
	days = s
print(days)


day = 0
for _ in range(int(input())):
	(s, d) = map(int, input().split())
	day = s + d * max((day - s) // d + 1, 0)
print(day)


n = int(input())
count = 0
for i in range(n):
	x = list(map(int, input().split(' ')))
	if x[0] > count:
		count = x[0]
	else:
		count = x[0] + ((count - x[0]) // x[1] + 1) * x[1]
print(count)


n = int(input())
x = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if s > x:
		x = s
	else:
		x = x - (x - s) % d + d
print(x)


n = int(input())
s = []
d = []
for _ in range(n):
	(a, b) = map(int, input().split())
	s.append(a)
	d.append(b)
days = s[0]
for i in range(1, n):
	(a, b) = (s[i], d[i])
	n = (days - a) // b
	if n * b + a <= days:
		days = (n + 1) * b + a
	else:
		days = n * b + a
	days = max(a, days)
print(days)


n = int(input())
(s, d) = [int(x) for x in input().split()]
ans = s
for i in range(2, n + 1):
	(s, d) = [int(x) for x in input().split()]
	if s > ans:
		ans = s
	elif (s - ans) % d == 0:
		ans += d
	else:
		ans += (s - ans) % d
print(ans)


def main():
	n = int(input())
	d = 0
	for i in range(n):
		d += 1
		(ini, ste) = list(map(int, list(input().split())))
		if d < ini:
			d = ini
		elif (d - ini) % ste != 0:
			d = d - (d - ini) % ste + ste
	print(d)
main()


n = int(input())
start = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a > start:
		start = a
	else:
		n = (start - a) // b + 1
		if a + (n - 1) * b > start:
			start = a + (n - 1) * b
		else:
			start = a + n * b
print(start)


n = int(input())
prev = 0
for _ in range(n):
	(start, diff) = map(int, input().split())
	if start > prev:
		prev = start
	else:
		prev = start + ((prev - start) // diff + 1) * diff
print(prev)


ans = 0
for _ in range(int(input())):
	(s, d) = map(int, input().split())
	if ans == 0:
		ans += s
	elif s > ans:
		ans = s
	else:
		t = s
		while t <= ans:
			t += d
		ans = t
print(ans)


def main():
	amount = int(input())
	current_day = 0
	for index in range(amount):
		(s, d) = map(int, input().split())
		day = s
		if day <= current_day:
			day += (current_day - day) // d * d
			while day <= current_day:
				day += d
		current_day = day
	print(current_day)
main()


n = int(input())
k = []
for _ in range(n):
	l = list(map(int, input().split()))
	k.append(l)
res = k[0][0]
for i in range(1, n):
	if k[i][0] > res:
		res = k[i][0]
	else:
		res = k[i][0] + ((res - k[i][0]) // k[i][1] + 1) * k[i][1]
print(res)


n = int(input())
h = 0
for i in range(n):
	(s, d) = map(int, input().split())
	h = max(s, h + d - (h - s) % d)
print(h)


n = int(input())
s = []
d = []
for _ in range(n):
	(si, di) = map(int, input().split())
	s.append(si)
	d.append(di)
ans = 0
for i in range(n):
	ans += 1
	si = s[i]
	di = d[i]
	if ans < si:
		ans = si
	else:
		ans = (ans - si + di - 1) // di * di + si
print(ans)


n = int(input())
(LAST, d) = map(int, input().split())
for i in range(n - 1):
	(s, d) = map(int, input().split())
	if s <= LAST:
		for j in range(s + d * ((LAST - s) // d), 10000001, d):
			if j > LAST:
				LAST = j
				break
	else:
		LAST = s
print(LAST)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
n = ip()
days = 0
for i in range(n):
	(s, d) = ei()
	if i == 0:
		days += s
	elif s > days:
		days += s - days
	else:
		i = 1
		while s + i * d <= days:
			i += 1
		days += s + i * d - days
print(days)


def main():
	n = int(input())
	t = 0
	for i in range(n):
		(s, d) = map(int, input().split())
		if t < s:
			t = s
		else:
			t += d - (t - s) % d
	print(t)
main()


n = int(input())
cnt = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a > cnt:
		cnt = a
	else:
		cnt = cnt - (cnt - a) % b + b
print(cnt)


n = int(input())
ans = 0
for i in range(n):
	(start, interval) = map(int, input().split())
	if start > ans:
		ans = start
	else:
		ans = ((ans - start) // interval + 1) * interval + start
print(ans)


import math
n = int(input())
cur = 0
for _ in range(n):
	(s, d) = map(int, input().split())
	if cur <= s:
		cur = s
	else:
		cur = s + math.ceil((cur - s) / d) * d
	cur += 1
print(cur - 1)


from functools import reduce
print(reduce(lambda res, s: s[0] + s[1] * ((res - s[0]) // s[1] + 1 * (res - s[0] % s[1] != 0 or res - s[0] == 0)) * (res - s[0] >= 0), [0] + [list(map(int, input().split())) for i in range(int(input()))]))


import math
n = int(input())
(a, b) = map(int, input().split())
x = a
for i in range(n - 1):
	(a, b) = map(int, input().split())
	if x > a:
		a = a + int((x - a) / b) * b
	while a <= x:
		a += b
	x = a
print(x)


def visit(doctors, i, ret):
	(s, d) = doctors[i]
	t = ret - s
	if t < 0:
		return s
	return (t + (d - 1)) // d * d + s
n = int(input())
doctors = []
for i in range(n):
	(s, d) = list(map(int, input().split(' ')))
	doctors.append((s, d))
ret = 0
for i in range(n):
	ret = visit(doctors, i, ret + 1)
print(ret)


n = int(input())
si = []
di = []
for i in range(n):
	(a, b) = map(int, input().split())
	si.append(a)
	di.append(b)
cur_day = si[0] + 1
for i in range(1, n):
	if si[i] < cur_day:
		temp = si[i]
		while True:
			if temp >= cur_day:
				cur_day = temp + 1
				break
			temp += di[i]
	elif si[i] == cur_day:
		cur_day += 1
	else:
		cur_day = si[i] + 1
print(cur_day - 1)


import math
n = int(input())
(s, d) = map(int, input().split())
m = s
for i in range(1, n):
	(s, d) = map(int, input().split())
	r = math.floor((m - s) / d + 1)
	if r < 0:
		r = 0
	m = s + r * d
print(m)


import math
n = int(input())
total = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if (total - a) % b == 0:
		total = max(0, math.ceil((total - a) / b) + 1) * b + a
	else:
		total = max(0, math.ceil((total - a) / b)) * b + a
print(total)


import math
n = int(input())
t = 0
for i in range(n):
	t += 1
	(s, d) = list(map(int, input().split()))
	k = max(math.ceil((t - s) / d), 0)
	t = s + d * k
print(t)


def main():
	n = int(input())
	day = 0
	for i in range(0, n):
		(s, d) = map(int, input().split())
		if day < s:
			day = s
		else:
			while True:
				s = s + d
				if day < s:
					day = s
					break
	print(day)
main()


from sys import stdin
input = stdin.readline
n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]
day = 1
for i in range(n):
	(s, d) = a[i]
	if day < s:
		day = s
	else:
		day += (d - (day - s) % d) % d
	day += 1
print(day - 1)


from math import ceil
n = int(input())
inp = [list(map(int, input().split())) for i in range(n)]
d = inp[0][0]
for i in inp[1:]:
	if not i[0] > d:
		d = i[0] + ceil((d + 1 - i[0]) / i[1]) * i[1]
	else:
		d = i[0]
print(d)


n = int(input())
day = 0
for i in range(n):
	(s, d) = map(int, input().split(' '))
	day = max(day + 1, s)
	while (day - s) % d != 0:
		day += 1
print(day)


n = int(input())
data = []
for i in range(n):
	data.append(tuple(map(int, input().split())))
cur = 0
for i in data:
	if i[0] > cur:
		cur = i[0]
		continue
	c = cur + 1 - i[0]
	c1 = c // i[1] + (c % i[1] > 0)
	cur = i[0] + i[1] * c1
print(cur)


n = int(input())
s = 0
for _ in range(n):
	(si, di) = map(int, input().split())
	k = max(0, (s - si + di - 1) // di)
	s = si + k * di + 1
print(s - 1)


(n, Day) = (int(input()), 0)
for i in range(n):
	(x, y) = map(int, input().split())
	if i == 0:
		Day = x
		continue
	while Day >= x:
		x += y
	Day = x
print(Day)


n = int(input())
r = 0
while n > 0:
	(s, d) = list(map(int, input().split()))
	r = max(r + 1, s)
	if (r - s) % d != 0:
		r += d - (r - s) % d
	n -= 1
print(r)


n = int(input())
s = 0
for i in range(n):
	(x, y) = map(int, input().split())
	while x <= s:
		x += y
	s = x
print(s)


u = []
for k in range(int(input())):
	(s1, d1) = map(int, input().split())
	u.append([s1, d1])
t = [u[0][0]]
if len(u) == 1:
	print(t[-1])
else:
	for j in range(1, len(u)):
		for x in range(u[j][0], 100000000, u[j][1]):
			if x > t[-1]:
				t.append(x)
				break
	print(t[-1])


import math
from operator import itemgetter
q = 1
while q > 0:
	q -= 1
	days = 0
	docs = int(input())
	days = [int(x) for x in input().strip().split(' ')][0]
	for _ in range(docs - 1):
		(a, b) = map(int, input().split(' '))
		if days < a:
			days = a
		elif days >= a:
			if not ((days - a) / b).is_integer():
				temp = int(math.ceil(math.ceil(days - a) / b))
				days = a + temp * b
			else:
				days += b
	print(days)


n = int(input())
ans = 0
for _ in range(n):
	(s, d) = map(int, input().split())
	if ans < s:
		ans = s
	else:
		ans += d - (ans - s) % d
print(ans)


n = int(input())
a = -1
for i in range(n):
	(p, q) = map(int, input().split())
	a = max(p, a + 1)
	while (a - p) % q:
		a += 1
print(a)


from math import ceil
n = int(input())
dr_schedule = []
for i in range(n):
	dr_schedule.append(input().split())
	dr_schedule[-1][0] = int(dr_schedule[-1][0])
	dr_schedule[-1][1] = int(dr_schedule[-1][1])
l = len(dr_schedule)
minDay = dr_schedule[0][0]
for i in range(1, l):
	if minDay < dr_schedule[i][0]:
		minDay += dr_schedule[i][0] - minDay
	else:
		jump = ceil((minDay - dr_schedule[i][0]) / dr_schedule[i][1])
		if dr_schedule[i][0] + jump * dr_schedule[i][1] == minDay:
			jump += 1
		minDay = dr_schedule[i][0] + jump * dr_schedule[i][1]
print(minDay)


from math import ceil
l = []
k = int(input())
for _ in range(k):
	(m, n) = map(int, input().split())
	l.append([m, n])
a = l[0][0]
for i in range(1, k):
	b = l[i][0]
	if b > a:
		a = b
	else:
		c = b + ceil((a - b) / l[i][1]) * l[i][1]
		if a == c:
			a += l[i][1]
		else:
			a = c
print(a)


n = int(input().strip())
schedule = [0]
for i in range(n):
	(a, b) = map(int, input().strip().split())
	schedule.append((a, b))
if n == 1:
	exit(print(schedule[1][0]))
day = 1
doc = 1
while True:
	(a, b) = schedule[doc]
	t = (day - a) / b
	if t == int(t) and t >= 0:
		doc += 1
	if doc == n + 1:
		break
	day += 1
print(day)


n = int(input())
doctors = []
for _ in range(n):
	(s, e) = map(int, input().split())
	doctors.append((s, e))
day = 1
doctor = 0
while True:
	(s, e) = doctors[doctor]
	if day >= s:
		if (day - s) % e == 0:
			doctor += 1
			if doctor == len(doctors):
				break
	day += 1
print(day)


n = int(input())
a = []
ans = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a <= ans:
		a += ((ans - a) // b + 1) * b
	ans = a
print(ans)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
n = ii()
a = [mi() for i in range(n)]
p = 0
for i in range(n):
	(s, d) = a[i]
	if s > p:
		p = s
	else:
		q = p - s
		p = s + d * (q // d + 1)
print(p)


n = int(input())
cur = 0
for i in range(n):
	(s, d) = map(int, input().split())
	while 1:
		if cur >= s and (cur - s) % d == 0:
			break
		cur += 1
	cur += 1
print(cur - 1)


from math import ceil
n = int(input())
(days, _) = map(int, input().split())
for i in range(n - 1):
	(a, d) = map(int, input().split())
	days = a + max(ceil((days + 1 - a) / d), 0) * d
print(days)


n = int(input())
s = 0
for i in range(n):
	(a, b) = map(int, input().split())
	h = s - a
	g = b - h % b
	s += g
	if h < 0:
		s = a
print(s)


n = int(input())
arr = [[0, 0] for i in range(n)]
for i in range(n):
	(arr[i][0], arr[i][1]) = map(int, input().split())
dates = [arr[0][0]]
for (i, j) in arr[1:]:
	while i <= dates[-1]:
		i += j
	dates.append(i)
print(dates[-1])


import collections
import random
import sys
n = int(input())
day = 0
for i in range(n):
	(s, d) = map(int, input().split())
	day = max(day + 1, s)
	if (day - s) % d != 0:
		day += d - (day - s) % d
print(day)


def main():
	n = int(input())
	day = 0
	for i in range(n):
		(s, d) = list(map(int, input().split()))
		if s > day:
			day = s
		else:
			day = ((day - s) // d + 1) * d + s
	print(day)
main()


n = int(input())
ans = 0
for i in range(n):
	(s, d) = map(int, input().split())
	s = max(s, s + d * ((ans - s) // d))
	for j in range(s, 10000000, d):
		if j > ans:
			ans = j
			break
print(ans)


n = int(input())
doc = []
for i in range(n):
	s = input()
	doc.append((i + 1, int(s.split()[0]), int(s.split()[1])))
count = 1
cd = 0
while cd < n:
	if count - doc[cd][1] >= 0 and (count - doc[cd][1]) % doc[cd][2] == 0:
		cd += 1
	count += 1
print(count - 1)


import math
t = int(input())
ans = 0
for i in range(t):
	(s, d) = list(map(int, input().split()))
	if i == 0:
		ans = s
	else:
		j = max(0, math.ceil((ans - s) / d))
		if s + d * j <= ans:
			j += 1
		ans = s + d * j
print(int(ans))


n = int(input())
(a, b) = map(int, input().split())
for i in range(n - 1):
	(a1, b1) = map(int, input().split())
	while a1 <= a:
		a1 = a1 + b1
	a = a1
print(a)


t = int(input())
i = 0
for x in range(t):
	l1 = [int(x) for x in input().split()]
	start = l1[0]
	freq = l1[1]
	if x == 0:
		i = start
	else:
		i += 1
		while i < start or (start - i) % freq:
			i += 1
print(i)


n = int(input())
days = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if i == 0:
		days = s
	else:
		j = 0
		while True:
			cal = s + j * d
			if cal > days:
				days = cal
				break
			j += 1
print(days)


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def solve():
	n = int(input())
	(days, _) = map(int, input().split())
	for i in range(n - 1):
		(a, d) = map(int, input().split())
		days = a + max(math.ceil((days + 1 - a) / d), 0) * d
	print(days)
t = 1
for _ in range(t):
	solve()


from math import ceil
n = int(input())
t = 0
days = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if s > days:
		days = s
	else:
		add = (days + 1 - s) / d
		days = s + ceil(add) * d
print(days)


n = int(input())
day = 1
for i in range(n):
	(start, extra) = map(int, input().split())
	day = max(day, start)
	while (day - start) % extra != 0:
		day += 1
	if i + 1 < n:
		day += 1
print(day)


import math
n = int(input().strip())
day = 0
for _ in range(n):
	day += 1
	(ai, di) = map(int, input().strip().split())
	if ai <= day:
		t = math.ceil((day - ai) / di)
		day = ai + t * di
	else:
		day = ai
print(day)


n = int(input())
SD = []
for i in range(n):
	(s, d) = map(int, input().split())
	SD.append((s, d))
cur = 0
for i in range(n):
	(s, d) = SD[i]
	if cur < s:
		cur = s
	elif cur > s:
		(q, r) = divmod(cur - s, d)
		cur = s + d * (q + 1)
	else:
		cur = s + d
print(cur)


n = int(input())
(s, d) = map(int, input().split())
last = s
for i in range(n - 1):
	(s, d) = map(int, input().split())
	c = max(0, last - s)
	c = (c + d) // d
	new = c * d + s
	if new - d >= last:
		new -= d
	if new <= last:
		new += d
	last = new
print(last)


n = int(input())
a = []
for i in range(n):
	a.append(tuple(map(int, input().split())))
day = a[0][0]
for i in range(1, n):
	if a[i][0] > day:
		day = a[i][0]
	else:
		day += 1
		day += (a[i][1] - (day - a[i][0]) % a[i][1]) % a[i][1]
print(day)


n = int(input())
(p, k) = list(map(int, input().split()))
na = []
na.append(p)
for x in range(n - 1):
	(p, k) = list(map(int, input().split()))
	if p <= na[-1]:
		x = (na[-1] - p) // k
		l = p + (x + 1) * k
		na.append(l)
	else:
		na.append(p)
print(na[-1])


from math import *
ans = 0
for _ in range(int(input())):
	(si, di) = list(map(int, input().split()))
	if si >= ans:
		ans = si + 1
		continue
	n = ans - si
	ans = si + ceil(n / di) * di + 1
print(ans - 1)


n = int(input())
actual = 1
for _ in range(n):
	(s, d) = list(map(int, input().split()))
	if actual <= s:
		actual = s
	elif (actual - s) % d != 0:
		actual += d - (actual - s) % d
	actual += 1
print(actual - 1)


n = int(input())
from math import ceil
a = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if s > a:
		a = s
	else:
		x = (a + 1 - s) / d
		a = s + ceil(x) * d
print(a)


import sys
import math
import bisect
import itertools
import random
import re

def main():
	cur = None
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		if _ == 0:
			cur = a
		else:
			cur += 1
			if cur < a:
				cur = a
			else:
				cur = a + (cur - a + b - 1) // b * b
	print(cur)
main()


n = int(input())
(a, b) = list(map(int, input().split()))
n -= 1
while n > 0:
	n -= 1
	(x, y) = list(map(int, input().split()))
	if a < x:
		a = x
	else:
		while a >= x:
			x += y
		a = x
print(a)


c = 0
for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = a if c - a < 0 else c + (b - (c - a) % b)
print(c)


r = 0
for _ in [0] * int(input()):
	(s, d) = map(int, input().split())
	r = [(r - s + d) // d * d + s, s][r < s]
print(r)


import math
from collections import defaultdict

def input_ints():
	return list(map(int, input().split()))

def solve():
	n = int(input())
	ans = 0
	for i in range(n):
		(s, d) = input_ints()
		while ans < s or ans % d != s % d:
			ans += 1
		ans += 1
	print(ans - 1)
solve()


n = int(input())
cur = 0
for i in range(n):
	(start, x) = [int(k) for k in input().split()]
	if cur < start:
		cur = start
	else:
		cur = start + ((cur - start) // x + 1) * x
print(cur)


t = int(input())
((s1, d1), k1) = (map(int, input().split()), 0)
for _ in range(t - 1):
	(s2, d2) = map(int, input().split())
	(s1, d1, k1) = (s2, d2, int((s1 + k1 * d1 - s2) / d2 + 1))
	if s2 > s1 + k1 * d1:
		k1 = 0
print(s1 + k1 * d1)


n = int(input())
(x, y) = map(int, input().split())
z = x
for i in range(n - 1):
	(x, y) = map(int, input().split())
	if z + 1 <= x:
		z = x
	else:
		z = x + ((z - x) // y + 1) * y
print(z)


a = 0
for i in range(int(input())):
	(s, d) = list(map(int, input().split()))
	a += 1
	while a < s or (a - s) % d != 0:
		a += 1
print(a)


n = int(input())
z = 0
for i in range(n):
	z += 1
	(s, d) = map(int, input().split())
	if z <= s:
		z = s
	else:
		x = s % d
		y = z % d
		if x >= y:
			f = (x - y) % d
			z += f
		else:
			f = (x - y) % d
			z += f
print(z)


n = int(input())
count = 0
for i in range(n):
	line = input().split(' ')
	s = int(line[0])
	d = int(line[1])
	if count < s:
		count = s
	else:
		r = count - s
		r = int(r / d) + 1
		count = r * d + s
print(int(count))


n = int(input())
s = []
d = []
for i in range(n):
	(si, di) = map(int, input().split())
	s.append(si)
	d.append(di)
x = s[0]
for i in range(1, n):
	if s[i] > x:
		x = s[i]
	else:
		y = x - s[i]
		s[i] += (y // d[i] + 1) * d[i]
		x = s[i]
print(x)


tCases = int(input())
appointment = []
ans = 0
for x in range(tCases):
	(a, b) = map(int, input().split())
	ans = a + ((ans - a) // b + 1) * b if ans >= a else a
print(ans)


import math
n = int(input())
s = []
for i in range(n):
	s.append([int(elem) for elem in input().split(' ')])
day = 1
for i in range(n):
	if s[i][0] > day:
		day = s[i][0]
	elif s[i][0] < day:
		day = s[i][0] + math.ceil((day - s[i][0]) / s[i][1]) * s[i][1]
	day += 1
print(day - 1)


n = int(input())
pehla = []
d = []
for i in range(n):
	(a, b) = map(int, input().split())
	pehla.append(a)
	d.append(b)
if n == 1:
	print(pehla[0])
	exit(0)
j = 1
i = pehla[0] + 1
while 1:
	if (i - pehla[j]) % d[j] == 0 and i >= pehla[j]:
		j += 1
	if j == n:
		break
	i += 1
print(i)


import math
n = int(input())
t = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if t < s:
		t = s
	else:
		t = s + (math.floor((t - s) / d) + 1) * d
print(t)


i = 0
num = int(input())
ls = []
while i < num:
	l = []
	temp = input()
	temp = temp.split(' ')
	l.append(int(temp[0]))
	l.append(int(temp[1]))
	ls.append(l)
	i += 1
temp = 0
p = 0
while p < num:
	if temp >= ls[p][0]:
		temp = (int((temp - ls[p][0]) / ls[p][1]) + 1) * ls[p][1] + ls[p][0]
	else:
		temp = ls[p][0]
	p += 1
print(temp)


n = int(input())
ret = 0
for i in range(n):
	(s, d) = map(int, input().split())
	temp = s
	while temp <= ret:
		temp += d
	ret = temp
print(ret)


time = 0
for i in range(int(input())):
	(s, d) = map(int, input().split())
	i = 1
	if s > time:
		time = s
	else:
		t = s
		while t <= time:
			t = s + d * i
			i = i + 1
		time = t
		s = t
print(s)


n = int(input())
min_day = 0
for i in range(n):
	(begin, end) = [int(i) for i in input().split()]
	if min_day < begin:
		min_day = begin
	else:
		min_day += end - (min_day - begin) % end
print(min_day)


n = int(input())
k = 0
for x in range(n):
	(s, d) = map(int, input().split())
	k += 1
	if s > k:
		k = s
	else:
		while (k - s) % d:
			k += 1
print(k)


n = int(input())
ans = 0
for i in range(n):
	(a, b) = map(int, input().split())
	while ans >= a:
		a += b
	ans = a
print(ans)


from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
import math
mod = pow(10, 9) + 7

def inp(flag=0):
	if flag == 0:
		return list(map(int, input().strip().split(' ')))
	else:
		return int(input())
n = inp(1)
days = 0
for i in range(n):
	(s, d) = inp()
	if i == 0:
		days = s
	else:
		j = 0
		while True:
			if s + j * d > days:
				days = s + j * d
				break
			j += 1
print(days)


def main():
	n = int(input())
	day = 0
	for _ in range(n):
		(s, d) = map(int, input().split())
		k = max(0, (day - s) // d)
		while s + k * d <= day:
			k += 1
		day = s + k * d
	print(day)
main()


import math
inp = lambda : list(map(int, input().split(' ')))
[n] = inp()
[day, d] = inp()
for i in range(n - 1):
	[s, d] = inp()
	j = math.floor((day - s) / d) + 1
	if j < 0:
		j = 0
	day = s + j * d
print(day)


n = int(input())
a = [[int(i) for i in input().split()] for j in range(n)]
summ = a[0][0]
for i in range(1, n):
	if summ + 1 <= a[i][0]:
		k = 0
	else:
		k = (summ - a[i][0] + 1) // a[i][1]
		if (summ - a[i][0] + 1) % a[i][1] > 0:
			k += 1
	summ = a[i][0] + k * a[i][1]
print(summ)


v = 1
for i in range(int(input())):
	(si, di) = map(int, input().split())
	while v < si or (v - si) % di:
		v += 1
	v += 1
print(v - 1)


n = int(input())
d = 1
s = 0
for i in range(0, n):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	s = d
	if i == 0 or d <= a:
		d = a
	else:
		import math
		e = math.ceil((d - a) / b)
		d = a + e * b
	if s >= d and i != 0:
		d += b
print(d)


n = int(input())
(s, d) = map(int, input().split())
D = s
for _ in range(1, n):
	(s, d) = map(int, input().split())
	if s > D:
		D = s
	else:
		k = (D - s) // d + 1
		D = s + k * d
print(D)


n = int(input())
day = 0
for _ in range(n):
	(s, d) = map(int, input().split())
	if day < s:
		day = s
	else:
		day = s + ((day - s) // d + 1) * d
print(day)


n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]
days = d[0][0]
d.remove(d[0])

def modulo(d, n):
	if d % n != 0:
		return 1
	else:
		return 0
for i in d:
	if i[0] <= days:
		i[0] = (int((days - i[0]) / i[1]) + modulo(days - i[0], i[1])) * i[1] + i[0]
	if days != i[0]:
		days = i[0]
	else:
		days = i[0] + i[1]
print(days)


from math import floor
n = int(input())
(s, d) = list(map(int, input().split()))
c = s
while n - 1:
	n -= 1
	(s, d) = list(map(int, input().split()))
	if s > c:
		c = s
	else:
		nth = (c - s) // d
		c = s + (nth + 1) * d
print(c)


n = int(input())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
day = l[0][0]
for i in range(1, n):
	while l[i][0] < l[i - 1][0] or l[i][0] == l[i - 1][0]:
		l[i][0] += (l[i - 1][0] - l[i][0]) // l[i][1] * l[i][1] + l[i][1]
	day = l[i][0]
print(day)


import math
import re
import os
import string
import sys

def ria():
	return [int(i) for i in input().split()]

def ri():
	return int(input())

def rfa():
	return [float(i) for i in input().split()]
eps = 1e-09

def is_equal(a, b):
	return abs(a - b) <= eps

def distance(p0, p1):
	return math.sqrt((p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2)

def distance_sqr(p0, p1):
	return (p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2
n = ri()
curD = 1
for i in range(n):
	(s, d) = ria()
	while s > curD or (curD - s) % d != 0:
		curD += 1
	curD += 1
print(curD - 1)


Input = lambda : map(int, input().split())
n = int(input())
(s, d) = Input()
Now_day = s + 1
for i in range(1, n):
	(s, d) = Input()
	if s == Now_day:
		Now_day += 1
	else:
		start = s
		while start < Now_day:
			start += d
		Now_day = start + 1
print(Now_day - 1)


n = int(input())
ans = 0
for i in range(n):
	(s, d) = list(map(int, input().split()))
	if ans == 0:
		ans = s
	elif s > ans:
		ans = s
	else:
		ans = d * ((ans - s) // d + 1) + s
print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	aa = [LI() for _ in range(n)]
	r = -1
	for (a, b) in aa:
		if r < a:
			r = a
		else:
			r = a + (r - a + b) // b * b
	return r
print(main())


doctors_nr = int(input())
doctor_idx___start_day_idx = []
doctor_idx___delta = []
for _ in range(doctors_nr):
	(start_day_idx, delta) = (int(x) for x in input().split())
	doctor_idx___start_day_idx.append(start_day_idx)
	doctor_idx___delta.append(delta)
doctors_visited_nr = 0
for day_idx in range(1, 3000000):
	curr_start_day_idx = doctor_idx___start_day_idx[doctors_visited_nr]
	curr_delta = doctor_idx___delta[doctors_visited_nr]
	if day_idx >= curr_start_day_idx and day_idx % curr_delta == curr_start_day_idx % curr_delta:
		doctors_visited_nr += 1
		if doctors_visited_nr == doctors_nr:
			print(day_idx)
			quit()


n = int(input())
today = 1
for _ in range(n):
	(s, d) = map(int, input().split())
	if today > s:
		today = s + (today - s + d - 1) // d * d + 1
	else:
		today = s + 1
print(today - 1)


a = int(input())
l = 0
for x in range(a):
	(b, c) = map(int, input().split())
	if x == 0:
		l = b
	elif b > l:
		l = b
	else:
		j = int((l - b) / c)
		l = b + c * (j + 1)
print(l)


import math
n = int(input())
current_day = 0
for i in range(0, n):
	current_day = current_day + 1
	(s, d) = [int(x) for x in input().split(' ')]
	p = max(0, math.ceil((current_day - s) / d))
	current_day = s + p * d
print(current_day)


n = int(input())
c = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if c < s:
		c = s
	else:
		c = s + ((c - s) // d + 1) * d
print(c)


from collections import deque
import math
ls = []
for i in range(int(input())):
	(n, k) = map(int, input().split())
	ls.append((n, k))
t = ls[0][0]
c = 0
for i in range(1, len(ls)):
	var = ls[i][0]
	if var <= t:
		c = math.ceil((t - ls[i][0]) / ls[i][1])
		if (t - ls[i][0]) % ls[i][1] == 0:
			c += 1
		t = ls[i][0] + ls[i][1] * c
	else:
		t = ls[i][0]
print(t)


import math
n = int(input())
currentfreeday = 0
for i in range(n):
	(si, di) = map(int, input().split())
	c = math.ceil((currentfreeday - si) / di)
	c = max(c, 0)
	igo = si + c * di
	currentfreeday = igo + 1
print(currentfreeday - 1)


n = int(input().strip())
days = 0
for _ in range(n):
	(s, d) = [int(i) for i in input().split()]
	if s > days:
		days = s
	else:
		n1 = (days - s) // d + 1
		days = s + n1 * d
print(days)


n = int(input())
nowday = 0
for i in range(0, n):
	(s, d) = map(int, input().split(' '))
	k = max(0, int((nowday - s) // d) - 1)
	while True:
		if nowday + 1 > s + k * d:
			k += 1
		else:
			nowday = s + k * d
			break
print(nowday)


import math
n = int(input())
a = [0] * 1000002
m = 0
for i in range(n):
	(x, y) = map(int, input().split())
	if x <= m:
		x = x + y * math.ceil((m - x) / y)
	for j in range(1000):
		if a[x + j * y] == 0:
			a[x + j * y] = 1
			if m < x + j * y:
				m = x + j * y
			break
print(m)


n = int(input())
days = 0
for _ in range(n):
	(s, d) = map(int, input().split())
	if s > days:
		days = s
	else:
		x = days - s + 1
		f = x / d
		if f > int(f):
			days = s + (int(f) + 1) * d
		elif f == int(f):
			days = s + int(f) * d
print(days)


import math
n = int(input())
res = 0
for i in range(n):
	(a, b) = map(int, input().split())
	res += 1
	kolb = max(0, math.ceil((res - a) / b))
	res = a + kolb * b
print(res)


n = int(input())
e = 0
for i in range(n):
	(a, b) = [int(i) for i in input().split()]
	if i == 0:
		e = a
	elif a <= e:
		while a <= e:
			a = a + b
		e = a
	else:
		e = a
print(e)


n = int(input())
days = [int(x) for x in input().split(' ')]
days = days[0]
for i in range(n - 1):
	(a, d) = [int(x) for x in input().split(' ')]
	if a > days:
		days = a
	else:
		days = a + ((days - a) // d + 1) * d
print(days)


l1 = []
l2 = []
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	l1.append(a)
	l2.append(b)
for i in range(1, n):
	if l1[i] <= l1[i - 1]:
		x = (l1[i - 1] - l1[i]) // l2[i]
		x += 1
		l1[i] = l1[i] + x * l2[i]
ma = l1[n - 1]
print(ma)


n = int(input())
t = 1
for i in range(n):
	(s, d) = map(int, input().split())
	if t <= s:
		t = s
	else:
		k = (t - s) // d
		while s + k * d < t:
			k += 1
		t = s + k * d
	t += 1
print(t - 1)


from math import ceil
n = int(input())
(c, d1) = map(int, input().split())
for _ in range(n - 1):
	(s, d) = map(int, input().split())
	a = d * ((c - s) // d + 1)
	c = s + a if a > 0 else s
print(c)


def main():
	n = int(input())
	min_v = 1
	for i in range(n):
		(s, p) = [int(v) for v in input().split()]
		min_v = max(s, min_v)
		ad = 1 if (min_v - s) % p != 0 else 0
		d = s + ((min_v - s) // p + ad) * p
		min_v = max(d, s) + 1
	print(min_v - 1)
main()


import math
n = int(input())
s = []
d = []
for i in range(n):
	inp = input().split()
	s.append(int(inp[0]))
	d.append(int(inp[1]))
ans = s[0]
for i in range(1, len(s)):
	if s[i] < ans:
		ans = d[i] * math.floor(1 + (ans - s[i]) / d[i]) + s[i]
	elif ans == s[i]:
		ans = s[i] + d[i]
	else:
		ans = s[i]
print(ans)


n = int(input())
count = 0
for i in range(n):
	(si, di) = map(int, input().split())
	if i == 0:
		count = si
	elif si <= count:
		t = (count - si) // di + 1
		count = si + di * t
	else:
		count = si
print(count)


from math import ceil
n = int(input().strip())
days = 0
for i in range(n):
	(a, b) = map(int, input().strip().split())
	days += 1
	x = max(0, ceil((days - a) / b))
	days = a + b * x
print(days)


ar = []
i = 0
for x in range(int(input())):
	ar.append(list(map(int, input().split())))
for x in ar:
	i = max(x[0], i + (x[0] - i - 1) % x[1] + 1)
print(i)


import math
n = int(input())
curday = 1
for i in range(n):
	inf = list(map(int, input().split()))
	k = math.ceil((curday - inf[0]) / inf[1])
	if k < 0:
		k = 0
	curday = inf[0] + k * inf[1] + 1
print(curday - 1)


n = int(input())
ans = 0
s = []
d = []
for i in range(n):
	(S, D) = map(int, input().split())
	s.append(S)
	d.append(D)
for i in range(n):
	if ans < s[i]:
		ans = s[i]
	else:
		k = (ans - s[i]) // d[i]
		ans = s[i] + (k + 1) * d[i]
print(ans)


n = int(input())
cur = 0
for i in range(n):
	(s, d) = [int(s) for s in input().split()]
	if cur < s:
		cur = s
	elif (cur - s) % d == 0:
		cur += d
	else:
		cur = s + ((cur - s) // d + 1) * d
print(cur)


import math
n = int(input())
sd = [tuple(map(int, input().split())) for _ in range(n)]
cd = 1
for i in range(n):
	s = sd[i][0]
	d = sd[i][1]
	if s >= cd:
		cd = s
	else:
		cd = s + math.ceil((cd - s) / d) * d
	cd += 1
cd -= 1
print(cd)


n = int(input())
dat = list()
for i in range(n):
	dat.append(list(map(int, input().split())))
day = dat[0][0]
for i in range(1, n):
	s = dat[i][0]
	d = dat[i][1]
	if s > day:
		day = s
	else:
		k = (day - s) // d
		day = s + (k + 1) * d
print(day)


import sys

def gint():
	return int(input())

def read():
	return map(int, input().split())
n = gint()
day = 0
for _ in range(n):
	(s, d) = read()
	day += 1
	k = (day - s - 1) // d + 1
	k = max(k, 0)
	day = s + d * k
print(day)


n = int(input())
(a, b) = map(int, input().split())
t = a
for i in range(n - 1):
	(a, b) = map(int, input().split())
	j = 0
	if a < t:
		j = (t - a) // b
	while True:
		if a + j * b > t:
			t = a + j * b
			break
		j += 1
print(t)


n = int(input())
result = 0
for i in range(n):
	(s, d) = map(int, input().split())
	k = max(result - s, 0) // d
	while s + k * d <= result:
		k += 1
	result = s + k * d
print(result)


from math import ceil
n = int(input())
c = 1
for _ in range(n):
	(s, d) = list(map(int, input().split()))
	if s >= c:
		c = s + 1
	else:
		i = ceil((c - s) / d)
		c = s + i * d + 1
print(c - 1)


from math import ceil
d = int(input())
a = list()
for k in range(d):
	(s, l) = input().split()
	a.append((int(s), int(l)))
t = a[0][0]
for i in a[1:]:
	(s, l) = i
	if s > t:
		t = s
	else:
		n = ceil((t - s + 1) / l)
		t = s + l * n
print(t)


import math
t = int(input())
D = 1
for j in range(t):
	(s, d) = [int(a) for a in input().split()]
	if D <= s:
		D = s
	else:
		n = math.ceil((D - s) / d)
		D = s + n * d
	if j < t - 1:
		D += 1
print(D)


import math
n = int(input())
t = -1
for doctor in range(n):
	(s, d) = [int(x) for x in input().split(' ')]
	if t < s:
		t = s
	else:
		t = s + d * ((t - s) // d + 1)
print(t)


cases = int(input())
ans = 0
while cases:
	cases -= 1
	(s, d) = map(int, input().split())
	last = ans
	if s > ans:
		ans = s
	else:
		while s <= ans:
			s += d
		ans = s
print(ans)


import math
c = 0
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if c < a:
		c = a
	else:
		d = a + b * math.ceil((c - a) / b)
		if d != c:
			c = d
		else:
			c = d + b
print(c)


n = int(input())
tmp = 0
for i in range(n):
	(a, b) = list(map(int, input().split()))
	if i is 0:
		tmp = a
		continue
	else:
		while a <= tmp:
			a += b
	tmp = a
print(tmp)


n = int(input())
ans = 0
for i in range(n):
	x = list(map(int, input().split()))
	if i == 0:
		ans = x[0]
	else:
		flag = 0
		while (ans - x[0]) % x[1] != 0 or ans < x[0]:
			ans += 1
			flag = 1
		if flag == 0:
			ans += x[1]
print(ans)


n = int(input())
ans = 0
for _ in range(n):
	(s, d) = [int(x) for x in input().split()]
	if ans >= s:
		t = (ans - s) // d
		s += (t + 1) * d
	ans = s
print(ans)


import sys
n = int(sys.stdin.readline())
cur_day = 0
for _ in range(n):
	(s, d) = map(int, sys.stdin.readline().split())
	if s > cur_day:
		cur_day = s
		continue
	cur_day = s + (cur_day - s + d) // d * d
print(cur_day)


import math
n = int(input())
schedules = []
for _ in range(n):
	schedules.append(tuple(map(int, input().split())))
day = 0
for (start, period) in schedules:
	lower_bound = (day - start) / period
	if lower_bound.is_integer():
		lower_bound = int(lower_bound + 1)
	else:
		lower_bound = math.ceil(lower_bound)
	lower_bound = max(0, lower_bound)
	day = start + period * lower_bound
print(day)


import math
n = int(input())
(jav, _) = map(int, input().split())
for i in range(n - 1):
	(m, k) = map(float, input().split())
	if m > jav:
		jav = m
	else:
		jav = (int(abs(jav - m) / k) + 1) * k + m
print(int(jav))


from math import *
n = int(input())
ans = 0
for i in range(n):
	gg = input()
	gg = gg.split()
	gg[0] = int(gg[0])
	gg[1] = int(gg[1])
	temp = ans - gg[0]
	if temp < 0:
		ans = gg[0]
	else:
		ans = (temp // gg[1] + 1) * gg[1] + gg[0]
print(ans)


n = int(input())
say = []
day = []
for i in range(n):
	(s, d) = list(map(int, input().split()))
	say.append(s)
	day.append(d)
ans = say[0]
for i in range(1, len(say)):
	if say[i] > ans:
		ans = say[i]
	elif say[i] + day[i] > ans:
		ans = say[i] + day[i]
	else:
		ans -= say[i]
		ans = (ans // day[i] + 1) * day[i] + say[i]
print(ans)


n = int(input())
sdi = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
	if ans < sdi[i][0]:
		ans = sdi[i][0]
	else:
		ans += sdi[i][1] - (ans - sdi[i][0]) % sdi[i][1]
print(ans)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
N = int(input())
ans = 0
for i in range(N):
	(s, d) = map(int, input().split())
	if ans >= s:
		diff = ans - s
		k = diff // d + 1
		ans = s + k * d
	else:
		ans = s
print(ans)


day = int(0)
for i in range(int(input())):
	(s, d) = map(int, input().split())
	newday = 0
	if day > s:
		newday = (int((day - s) / d) + 1) * d + s
	else:
		newday = s
	if newday == day:
		day += d
	else:
		day = newday
print(str(day))


import math

def round_school(x):
	(i, f) = divmod(x, 1)
	return int(i + (f >= 0.5 if x > 0 else f > 0.5))
x = int(input())
current = -1
for _ in range(x):
	(s, d) = map(int, input().split())
	if current == -1:
		current = s
	else:
		remain = current - s
		if remain < 0:
			current = s
		else:
			remain = remain / d
			remain = math.floor(remain) + 1
			current = s + d * remain
print(current)


n = [[int(x) for x in input().split()] for _ in range(int(input()))]
t = 1
for (s, d) in n:
	if t <= s:
		t = s + 1
		continue
	dt = (t - s) // d
	t = s + d * dt if d * dt == t - s else s + d * (dt + 1)
	t += 1
print(t - 1)


N = int(input())
Last = list(map(int, input().split()))[0]
for i in range(1, N):
	X = list(map(int, input().split()))
	Last = X[0] if X[0] > Last else X[0] + ((Last - X[0]) // X[1] + 1) * X[1]
print(Last)


from math import ceil

def main():
	n = int(input())
	doctors = [{}] * n
	for i in range(n):
		[s, d] = [int(_) for _ in input().split()]
		doctors[i] = {'first_day': s, 'delay': d}
	day = doctors[0]['first_day']
	for i in range(1, n):
		min_x = max(0, (day - doctors[i]['first_day']) // doctors[i]['delay'] + 1) if (day - doctors[i]['first_day']) % doctors[i]['delay'] == 0 else max(0, ceil((day - doctors[i]['first_day']) / doctors[i]['delay']))
		day = doctors[i]['first_day'] + doctors[i]['delay'] * min_x
	print(day)
main()


n = int(input())
c = 0
for i in range(n):
	c += 1
	(s, d) = map(int, input().split())
	c = c + (s - c) % d
	c = max(s, c)
print(c)


n = int(input())
u = 0
for i in range(n):
	(s, d) = map(int, input().split(' '))
	if s > u:
		u = s
	elif s == u:
		u = s + d
	else:
		u = s + round(d * ((u - s) // d + 1))
print(u)


n = int(input())
ans = 0
c = 1
import math
for i in range(n):
	(s, d) = map(int, input().split())
	p = int(math.ceil(max(0, c - s) / d))
	c = s + p * d + 1
print(c - 1)


n = int(input())
day = 0
while n > 0:
	n -= 1
	(s, d) = list(map(int, input().split()))
	if s > day:
		day = s
	else:
		m = (day - s) // d
		day = s + d * (m + 1)
print(day)


n = int(input())
(s, d) = map(int, input().split())
x = s
for i in range(n - 1):
	(s, d) = map(int, input().split())
	i = 1
	if s == x:
		x = s + d
	elif s < x:
		s += ((x - s) // d + 1) * d
		x = s
	else:
		x = s
print(x)


n = int(input())
prev = 0
for _ in range(n):
	(start, diff) = map(int, input().split())
	while start <= prev:
		start += diff
	prev = start
print(prev)


import math
n = int(input())
(a, b) = map(int, input().split())
min_day = a
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	if min_day + 1 <= a:
		min_day = a
	else:
		x = math.ceil(abs(a - (min_day + 1)) / b)
		min_day = a + x * b
print(min_day)