Codeforces Round 443 (Div. 2)
A
Borya's Diagnosis
Codeforces
900
原题
←B →
翻译中…

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*} + 2*d*_{*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.

翻译中…

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$.

翻译中…

样例

Input #1
3
2 2
1 2
2 2
Output #1
4
InputCopy OutputCopy
Input #2
2
10 1
6 5
Output #2
11
InputCopy OutputCopy
题目信息
题号
879A
时间限制
2 s
内存限制
256 MB
标签
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。