Adding some more judges, here and there.
[and.git] / NEERC / business / business_ia_vd.java
blob31e4039346f9fc3c7cee5c0c2730cf78a760f04d
1 import java.io.*;
2 import java.util.Scanner;
4 /**
5 * @author Iskander Akishev
6 * @author Vladimir Danilov
7 */
8 public class business_ia_vd implements Runnable {
10 private static final String FILE_NAME = "business";
12 public void run() {
13 try {
14 solve();
15 } catch (Throwable t) {
16 t.printStackTrace();
17 System.exit(1);
21 private Scanner in;
22 private PrintWriter out;
24 private void solve() throws Exception {
25 in = new Scanner(new FileReader(FILE_NAME + ".in"));
26 out = new PrintWriter(new File(FILE_NAME + ".out"));
28 try {
29 int n = in.nextInt();
30 int m = in.nextInt();
32 int res = 1000000000;
33 for (int i = 0; i < m; i++) {
34 int u = in.nextInt();
35 int d = in.nextInt();
37 int upOnly = u * n;
38 int mod = upOnly % (u + d);
39 res = Math.min(res, mod == 0 ? u + d : mod);
42 out.print(res);
43 } finally {
44 in.close();
45 out.close();
49 public static void main(String[] args) {
50 new Thread(new business_ia_vd()).start();