#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> arr1(m), arr2(m);
    for (int j = 0; j < m; j++) {
        cin >> arr1[j] >> arr2[j];
    }

    // 遍历每张优惠券统计相应支付金额
    vector<int> arr3(m);
    for (int j = 0; j < m; j++) {
         if (n >= arr1[j]) {
            arr3[j] = n - arr2[j];
        }else {
            arr3[j] = n;
        }
    }

    // 对价格进行排序
    sort(arr3.begin(), arr3.end());

    cout << arr3[0];
}
// 64 位输出请用 printf("%lld")
  1. 先求值再排序:最终要在一堆数字里面找最小值,那么就可以先都算出来再用sort排序。
  2. 遍历求值:求值就是要一个个算,所以要遍历。
  3. 分类讨论:对于每个数字,都有能用优惠券和不能用优惠券两种情况,所以要分支。