#include<bits/stdc++.h>
using namespace std;

int main(){
    int n, h;
    cin >> h >> n;
    vector<int> a(n), b(n), dp(h+1,1e9);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < h + 1; j++) {
            dp[min(j + a[i], h)] = min(dp[min(j + a[i], h)], dp[j] + b[i]);
        }
    }
    cout << dp[h] << endl;
    return 0;
}