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

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto N = s[1];
    auto A = iota(N).map!(_ => readln.split.map!(to!int).array).array;

    auto dp = new int[](H+1);
    dp[] = 1 << 29;
    dp[0] = 0;

    foreach (i; 0..H) foreach (a; A) {
        if (i + a[0] <= H) dp[i + a[0]] = min(dp[i + a[0]], dp[i] + a[1]);
        else dp[H] = min(dp[H], dp[i] + a[1]);
    }

    dp[H].writeln;
}