eolymp
bolt
Try our new interface for solving problems
Məsələlər

Business Center

Business Center

International Cyber Police Corporation (ICPC) had built a new mega-tall business center to host its headquarters and to lease some space for extra profit. It has so many floors, that it is impractical to have a separate button in each of its \textit{m }elevator cars for each individual floor. Instead, each elevator car has just two buttons. One button in \textit{i}-th elevator car makes it move up \textit{u_i }floors, the other makes it move down \textit{d_i} floors. The business center is so high, that we can ignore its height for this problem (you will never reach the top floor), but you cannot go below the ground floor. All floors are numbered by integer numbers starting from zero, zero being the ground floor. You start on the ground floor of the business center. You have to choose one elevator car out of \textit{m }to ride on. You cannot switch elevators cars after that. What is the lowest floor above the ground floor you can get to after you press elevator car buttons exactly \textit{n }times? \InputFile The first line of the input file contains two integer numbers \textit{n }and \textit{m }(1 <= \textit{ n }<=\textit{ }1 000 000, 1 <=\textit{ m }<=\textit{ }2000) -- the number of button presses and the number of elevator cars to choose from. The following \textit{m }lines describe elevator cars. Each line contains two integer numbers \textit{u_i }and \textit{d_i }(1 <=\textit{ u_i}, \textit{d_i }<=\textit{ }1 000). \OutputFile Write to the output file a single positive integer number -- the number of the lowest floor above ground floor that can be reached by one of \textit{m }elevators after pressing its buttons exactly \textit{n }times.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
10 3
15 12
15 4
7 12
Çıxış verilənləri #1
13
Müəllif Roman Elizarov