import java.util.Scanner;
import java.util.HashMap;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextLine()) {
String s = scanner.nextLine();
int cartAmount = Integer.parseInt(s.split(" ")[0]);
int num = Integer.parseInt(s.split(" ")[1]);
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < num; i++) {
String str = scanner.nextLine();
map.put(Integer.parseInt(str.split(" ")[0]),
Integer.parseInt(str.split(" ")[1]));
}
HashMap<Integer, Integer> map1 = new HashMap<>();
for (Integer integer : map.keySet()) {
if (integer <= cartAmount) {
map1.put(integer, cartAmount - map.get(integer));
}
}
if(map1.keySet().size()==0){
System.out.println(cartAmount);
break;
}
//100 3
//300 50
//200 30
//50 5
int minValue = Integer.MAX_VALUE;
for (Integer value : map1.values()) {
if (value < minValue) {
minValue = value;
}
}
System.out.println(minValue);
}
}
}
厉害了我



京公网安备 11010502036488号