module kkk
  sub main()
    
    dim h as long
    dim n as long
    dim hn
    dim ab
    
    hn = console.readline()
    hn = split(hn, " ")
    h = hn(0)
    n = hn(1)
    
    dim a() as long
    dim b() as long
    dim kor as double
    dim max as double
    dim min() as long
    dim am as long
    dim bm as long
    dim minb as long
    
    dim i as long
    dim j as long
    dim k as long
    
    redim a(n - 1)
    redim b(n - 1)
    redim min(n - 1)
    
    for i = 0 to n - 1
    ab = console.readline()
    ab = split(ab, " ")
    a(i) = ab(0)
    b(i) = ab(1)
    kor = a(i) / b(i)
    if max < kor then
      max = kor
      am = a(i)
      bm = b(i)
    end if
    min(i) = b(0)
    for j = 0 to n - 1
    if k < a(j) then
      if min(i) > b(j) then
        min(i) = b(j)
        if minb >= min(i) then
          minb = min(i)
        end if
      end if
    end if
  next
  next
    
  i = 1
  do 
    k = h - am * i
    if k <= 0 then
      i = i - 1
      k = h - am * i
      exit do
      end if
      i = i + 1
    loop
    
    
  
  console.writeline(i * bm + minb)
end sub
end module
    