import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

void main() {
    int H, N;
    scan(H, N);
    auto a = new int[](N);
    auto b = new int[](N);
    iota(N).each!(i => scan(a[i], b[i]));

    const lim = H + a.reduce!max + 1;

    auto dp = new long[][](N + 1, lim);
    fillAll(dp, infl);
    dp[0][0] = 0;

    foreach (i; 1 .. N + 1) {
        foreach (x; 0 .. lim) {
            chmin(dp[i][x], dp[i-1][x]);
            if (x - a[i-1] >= 0) {
                chmin(dp[i][x], dp[i][x - a[i-1]] + b[i-1]);
            }
        }
    }

    long ans = infl;
    foreach (x; H .. lim) {
        chmin(ans, dp[N][x]);
    }
    writeln(ans);
}

void scan(T...)(ref T args) {
    auto line = readln.split; // @suppress(dscanner.suspicious.unmodified)
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}
