/*********************************************
* 20.05.19 AtCoder Beginner Contest 153
* 
* 
*********************************************/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int (i)=1;(i)<=(n);i++)
#define rez(i,n) for(int (i)=0;(i)<(n);i++)
#define et "\n"

class CRun{
private:
    void IO_faster();
public:
    char problem_num;
    
    CRun(){
        problem_num = 'E';
    }; 
    ~CRun(){};
    void build();
    void solve_A(); void solve_B(); void solve_C(); 
    void solve_D(); void solve_E(); void solve_F();
};

void CRun::IO_faster(){
    ios::sync_with_stdio(0); cin.tie(NULL);
}

/*********************************************
A - Serval vs Monster
敵の体力H
味方の攻撃1回で体力をA減らせる
勝つための攻撃回数は？
*********************************************/
void CRun::solve_A(){
    int H; cin >> H;
    int A; cin >> A;
    
    int ans = 0;
    //ans += (H % A > 0 ? H / A + 1 : H / A);
    ans += (H - 1) / A + 1;
    cout << ans;
}

/*********************************************
B - Common Raccoon vs Monster
モンスターの体力H
N種類の攻撃で敵のHPをAN減らせる
同じ攻撃を使わずに敵を倒せるか？
*********************************************/
void CRun::solve_B(){
    
    int H; cin >> H;
    int N; cin >> N;
    int A[N]; rez(i,N) cin >> A[i];
    
    int sum = 0;
    for (auto &ix : A) sum += ix;
    
    string ans[] = {"Yes", "No"};
    if (sum >= H) {
        cout << ans[0];
    }
    else {
        cout << ans[1];
    }
    
}

/*********************************************
C - Fennec vs Monster
N개체의 적, H_N 만큼의 체력
공격 : 적을 1개체 골라서 체력을 1만큼 줄임
필살 : 적을 1개체 골라서 체력을 0으로 만듦
K회만큼 필살기를 쓸 수 있을 때, 승리하는 공격의 최소횟수는?
*********************************************/
void CRun::solve_C(){
    this->IO_faster();
    int enemy_num; cin >> enemy_num;
    int ultimate_cnt; cin >> ultimate_cnt;
    int enemy_hp[enemy_num]; rez(i,enemy_num) cin >> enemy_hp[i];
    
    ll ans = 0;
    sort(enemy_hp, enemy_hp + enemy_num, greater<int>());
    for (int ix = ultimate_cnt; ix < enemy_num; ix++) {
        ans += enemy_hp[ix];
    }
    cout << ans;
}

/*********************************************
D - Caracal vs Monster
적의 체력 H
적을 1개체 선택해서 공격가능. 
- 몬스터의 체력이 1이라면, 그 몬스터의 체력은 0이 된다
- 몬스터의 체력이 1보다 크면, 소멸하고 체력이 X/2인 몬스터가 2체 생성
승리하기 위한 최소 공격횟수?
*********************************************/
void CRun::solve_D(){
    ll H; cin >> H;
    int power = 0;
    while (H > 0) {
        H>>=1;
        power += 1;
    }
    
    long ans = 0;
    while (power-- > -1) {
        ans += pow(2,power);
    }
    
    cout << ans << et;
}

/*********************************************
E - Crested Ibis vs Monster
敵の体力H
N種類の魔法で敵の体力をAi減らせるのができる。この時、魔力をBi消耗する。
勝つため必要な魔力の最小値は？
*********************************************/
void CRun::solve_E(){
    
    //abort
    /*
    int H; cin >> H;
    int N; cin >> N;
    pair<int, int> magic[N];
    for (int ix = 0; ix < N; ix++) {
        int A, B; cin >> A >> B;
        magic[ix].first = A;
        magic[ix].second = B;
    }
    sort(magic, magic + N, [](auto &l, auto &r) {
        float power_l = l.first / l.second;
        float power_r = r.first / r.second;
        return power_l > power_r;
    });
    for (auto &ix : magic) {
        cout << ix.first << " " << ix.second << et;
    }
    */
    
    int H; cin >> H;
    int N; cin >> N;
    int A[N]; //matk
    int B[N]; //mp
    rez(i,N) cin >> A[i] >> B[i];
    
    ll dp[H + 1];
    fill(dp, dp + sizeof(dp)/sizeof(dp[0]), LONG_MAX - 1e6);
    dp[0] = 0;
    for (int ix = 0; ix < N; ix++) {
        for (int jx = 0; jx < H; jx++) {
            dp[min(H, jx + A[ix])] = min(dp[min(H, jx + A[ix])], dp[jx] + B[ix]); 
        }
    }
    
    cout << dp[H];
}

/*********************************************

*********************************************/
void CRun::solve_F(){
    
}

int main(){
    CRun run;
    switch (run.problem_num) {
        case 'A' : run.solve_A();
        case 'B' : run.solve_B();
        case 'C' : run.solve_C();
        case 'D' : run.solve_D();
        case 'E' : run.solve_E();
        case 'F' : run.solve_F();
    }
}



Measured memory_bytes: 384