namespace AtCoderCS
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using System.Linq;
    using static System.Console;
    using static System.Math;
    using static Macro;
    using static Ex;
    using static Library;

    class Program
    {
        void Solve()
        {
            var H = IN.Int;
            var N = IN.Int;
            var A = new int[N];
            var B = new int[N];
            REP(N, i =>
            {
                A[i] = IN.Int;
                B[i] = IN.Int;
            });
            var dp = new int[H + 1];
            REP(dp.Length, i => dp[i] = Int32.MaxValue);
            dp[H] = 0;
            for (var i = H; i >= 0; i--)
            {
                if(dp[i] == Int32.MaxValue) continue;
                for (var j = 0; j < N; j++)
                {
                    var idx = Max(0, i - A[j]);
                    dp[idx] = Min(dp[idx], dp[i] + B[j]);
                }
            }
            WriteLine(dp[0]);
        }

        private SimpleInput IN = new SimpleInput();
        private SimpleOutput OUT = new SimpleOutput();

        void Stream()
        {
            Solve();
            OUT.Flush();
        }

        static void Main(string[] args)
            => new Program().Stream();
    }


    #region IO

    class SimpleInput
    {
        private string[] _nextBuffer;
        private int _bufferCnt;
        private readonly char[] _cs = new char[] {' ', '"', ','};

        public SimpleInput()
        {
            _nextBuffer = new string[0];
            _bufferCnt = 0;
        }

        string Next()
        {
            if (_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++];
            var st = ReadLine();
            while (st == string.Empty) st = ReadLine();
            if (st != null) _nextBuffer = st.Split(_cs, StringSplitOptions.RemoveEmptyEntries);
            _bufferCnt = 0;
            return _nextBuffer[_bufferCnt++];
        }

        public string String => Next();
        public char Char => char.Parse(String);
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
    }

    class SimpleOutput
    {
        private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput())
        {
#if DEBUG
            AutoFlush = true
#else
            AutoFlush = false
#endif
        };

        public SimpleOutput()
        {
            SetOut(_sw);
        }

        public void Flush() => Out.Flush();
    }

    #endregion

    #region MACRO

    static class Macro
    {
        public static void FOR(int a, int b, int n, Action<int> f)
        {
            for (int i = a; i < b; i += n) f(i);
        }

        public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f);
        public static void REP(int a, Action<int> f) => FOR(0, a, 1, f);
        public static IEnumerable<TResult> ZIP<T1, T2, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys,
            Func<T1, T2, TResult> f = null)
        {
            using (var e1 = xs.GetEnumerator())
            using (var e2 = ys.GetEnumerator())
                while (e1.MoveNext() && e2.MoveNext())
                    yield return f(e1.Current, e2.Current);
        }
 
        public static IEnumerable<Tuple<T1, T2>> ZIP<T1, T2>(IEnumerable<T1> xs, IEnumerable<T2> ys)
            => ZIP(xs, ys, (x, y) => new Tuple<T1, T2>(x, y));
 
        public static IEnumerable<TResult> ZIP<T1, T2, T3, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys,
            IEnumerable<T3> zs, Func<T1, T2, T3, TResult> f)
        {
            using (var e1 = xs.GetEnumerator())
            using (var e2 = ys.GetEnumerator())
            using (var e3 = zs.GetEnumerator())
                while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext())
                    yield return f(e1.Current, e2.Current, e3.Current);
        }
 
        public static IEnumerable<Tuple<T1, T2, T3>> ZIP<T1, T2, T3>(IEnumerable<T1> xs, IEnumerable<T2> ys,
            IEnumerable<T3> zs) => ZIP(xs, ys, zs, (x, y, z) => new Tuple<T1, T2, T3>(x, y, z));
    }

    #endregion

    #region Ex

    static class Ex
    {
        public static string AsString(this IEnumerable<char> xs) => new string(xs.ToArray());
        public static void Print<T>(this T x) => WriteLine(x);
        public static string Yn(this bool x, string y = "Yes", string n = "No") => x ? y : n;
        public static string YN(this bool x) => x.Yn("YES", "NO");
        public static IEnumerable<T[]> Windowed<T>(this IEnumerable<T> xs, int size)
        {
            if (size <= 0) throw new ArgumentException();
            var w = new T[size];
            var r = size - 1;
            var i = 0;
            using (var e = xs.GetEnumerator())
            {
                while (e.MoveNext())
                {
                    w[i] = e.Current;
                    i = (i + 1) % size;
                    if (r == 0)
                    {
                        var ret = new T[size];
                        Array.Copy(w, i, ret, 0, size - i);
                        Array.Copy(w, 0, ret, size - i, i);
                        yield return ret;
                    }
                    else r--;
                }
            }
        }
    }
    #endregion
    
    #region Library

    static class Library
    {
        public static int BinarySearch(int ng, int ok, Func<int, bool> f)
        {
            while (Math.Abs(ok - ng) > 1)
            {
                var mid = (ok + ng) / 2;
                if (f(mid)) ok = mid;
                else ng = mid;
            }

            return ok;
        }

        public static int LowerBound<T>(IReadOnlyList<T> a, T x) where T : IComparable<T> =>
            BinarySearch(-1, a.Count, (m) => a[m].CompareTo(x) >= 0);

        public static int UpperBound<T>(IReadOnlyList<T> a, T x) where T : IComparable<T> =>
            BinarySearch(-1, a.Count(), (m) => a[m].CompareTo(x) > 0);
    }

    #endregion
}

Measured memory_bytes: 11192