let [|h;n|] = stdin.ReadLine().Split() |> Array.map int
let ab = Array.init n (fun _ -> stdin.ReadLine().Split() |> Array.map int)

let arr = Array.init n (fun i -> ((float ab.[i].[0] / float ab.[i].[1],ab.[i].[0],ab.[i].[1])))
let set1  = Set.ofArray arr

let rec max1 (st:Set<float*int*int>) mp damage = 
 match mp with
 | y when y <= 0 -> damage
 | _ when (st |> Set.isEmpty) -> damage
 | _ -> let (ritu_m,a_m,b_m) = st |> Set.maxElement
        let kaisu = mp / b_m
        let st_new = Set.remove (ritu_m,a_m,b_m) st
        max1 st_new (mp - (kaisu * b_m)) (min h (damage + kaisu * a_m))

let f mp = (max1 set1 mp 0) >= h

let rec nibun lb ub =
 match (ub - lb) with
 | 1 -> ub
 | _ -> let mid = (lb + ub) / 2
        if f mid then nibun lb mid else nibun mid ub

nibun 0 100000000
|>stdout.WriteLine