Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $n$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $d$ rubles, and one euro costs $e$ rubles.

Recall that there exist the following dollar bills: $1$, $2$, $5$, $10$, $20$, $50$, $100$, and the following euro bills — $5$, $10$, $20$, $50$, $100$, $200$ (note that, in this problem we do not consider the $500$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.

Help him — write a program that given integers $n$, $e$ and $d$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills.


-----Input-----

The first line of the input contains one integer $n$ ($1 \leq n \leq 10^8$) — the initial sum in rubles Andrew has. 

The second line of the input contains one integer $d$ ($30 \leq d \leq 100$) — the price of one dollar in rubles. 

The third line of the input contains integer $e$ ($30 \leq e \leq 100$) — the price of one euro in rubles.


-----Output-----

Output one integer — the minimum number of rubles Andrew can have after buying dollar and euro bills optimally.


-----Examples-----
Input
100
60
70

Output
40

Input
410
55
70

Output
5

Input
600
60
70

Output
0



-----Note-----

In the first example, we can buy just $1$ dollar because there is no $1$ euro bill.

In the second example, optimal exchange is to buy $5$ euro and $1$ dollar.

In the third example, optimal exchange is to buy $10$ dollars in one bill.

Difficulty: competition

Starter code:

Solutions:
n = int(input())
d = int(input())
e = 5*int(input())

ans = n
d, e = min([d, e]), max([d, e])

for i in range(e):
    if (n-i*d) >= 0:
        ans = min([ans, (n-i*d)%e])
        
print(ans)

def main():
    import sys
    input = sys.stdin.readline
    
    n = int(input())
    d = int(input())
    e = int(input()) * 5
    
    mi = n
    i = 0
    while i * e <= n:
        mi = min(mi, (n - i * e) % d)
        i += 1
    
    print(mi)
    
    return 0

main()


n=int(input())
d=int(input())
e=int(input())*5

ans=10**8+1
for i in range(d):
    k=n-e*i
    if k<0:
        break
    ans=min(ans, k%d)

print(ans)

import sys
input = sys.stdin.readline
 
def getInt(): return int(input())
def getVars(): return map(int, input().split())
def getList(): return list(map(int, input().split()))
def getStr(): return input().strip()
## -------------------------------

def addDictList(d, key, val):
    if key not in d: d[key] = []
    d[key].append(val)

def addDictInt(d, key, val):
    if key not in d: d[key] = 0
    d[key] = val
    
def addDictCount(d, key):
    if key not in d: d[key] = 0
    d[key] += 1

def addDictSum(d, key, val):
    if key not in d: d[key] = 0
    d[key] += val

## -------------------------------

n = getInt()
d = getInt()
e = getInt()

m1 = max(d, e*5)
m2 = min(d, e*5)


res = n%m1
for x in range(n//m1+1):
    res = min(res, (n-x*m1)%m2)
print(res)

rubes = int(input())
d = int(input())
e = int(input()) * 5

ans = rubes 
for i in range(rubes // e + 1):
    ans = min(ans, (rubes - i*e) % d)
print(ans)

n = int(input())    
d = int(input())
e = int(input())
e *= 5
res = n
for i in range((n // e) + 1):
    res = min(res, (n - i * e) % d)
print(res)

n = int(input())
d = int(input())
e = int(input())

e = 5*e

curr = 0
mini = n

while curr <= n:
    if (n-curr)%e < mini:
        mini = (n-curr)%e
    curr += d

print(mini)

n = int(input())
d = int(input())
e = int(input())

e *= 5

dollar = 0
ans = n
while d * dollar <= n:
    val = n - d*dollar
    ans = min(ans, val % e)
    dollar += 1

print(ans)

n=int(input())
d=int(input())
e=int(input())*5
d,e=max(d,e),min(d,e)
v=n
for i in range(e):
    m=n-i*d
    if m<0:
        break
    m%=e
    v=min(v,m)
print(v)

n = int(input())
d = int(input())
e = int(input())

ans = n % d
for i in range(100000):
    if 5 * e * i <= n:
        k = n - 5 * e * i
        if ans > k % d:
            ans = k % d

print(ans)

def gcd(x,y):
    if(y==0):
        return x
    return gcd(y,x%y)
 
 
n = int(input())
d = int(input())
e = int(input())
e*= 5
if(n > 10*e*d):
    print(n % gcd(e,d))
    return
 
ans = [0]
 
for i in range(1, n + 1):
    ans.append(i)
    if(i >= d):
        ans[i] = min(ans[i], ans[i - d])
    if(i >= e):
        ans[i] = min(ans[i], ans[i - e])
# print(ans)
print(ans[n])

import sys 
from collections import defaultdict
input = lambda : sys.stdin.readline().rstrip()

n = int(input())
d = int(input())
e = int(input())

dollar = d 
euro = 5 * e 

ans = n 

if n % dollar == 0 or n % euro == 0:
  print(0)
  return

for i in range(n // dollar + 1):
  k = n - i * dollar
  k -= (k // euro) * euro

  ans = min(ans, k)

for i in range(n // euro + 1):
  k = n - i * euro
  k -= (k // dollar) * dollar 

  ans = min(ans, k)



print(ans)


# from collections import Counter
#
# x = """100
# 60
# 70"""
#
# x = """410
# 55
# 70"""
#
# x = """600
# 60
# 70"""
#
# def f(string):
#     def c(x =(r for r in string.splitlines())):
#         return next(x)
#
#     return c
#
# source = f(x)

source = input

amount = int(source())
price_dollar = int(source())
price_euro = int(source())

def get_answer(amount, p1, p2):
    best = amount
    for other in range(p1):
        a1 = amount - other * p2
        if a1 == 0:
            return 0

        if a1 < 0:
            break

        change = a1 % p1
        best = min(change, best)

    return best

print(get_answer(amount, price_dollar, price_euro * 5))






n = int(input())
d = int(input())
e = int(input()) * 5

r = n
for i in range(d):
    if i * e > n:
        continue
    p = (n - i * e) - (n - i * e) // d * d
    r = min(r, p)
print(r)


#!/usr/bin/env python3
import sys

def rint():
    return list(map(int, sys.stdin.readline().split()))
#lines = stdin.readlines()


n = int(input())
d = int(input())
e = int(input())

d_min = d
e_min = 5*e

min1, min2 = sorted([d_min, e_min])

ans = 10**10
for i in range(0, min1+1):
    tmp = n - i*min2
    if tmp < 0:
        break
    tmp = tmp%min1
    ans = min(tmp, ans)

print(ans)


n=int(input())
d=int(input())
e=int(input())
a=e*5
m=10000000
for i in range(min(100,n//a+1)):
	if ((n-a*i)%d)<m:
		m=(n-a*i)%d
print (m)

import math
import sys
import collections

# imgur.com/Pkt7iIf.png

def getdict(n):
    d = {}
    if type(n) is list:
        for i in n:
            if i in d:
                d[i] += 1
            else:
                d[i] = 1
    else:
        for i in range(n):
            t = ii()
            if t in d:
                d[t] += 1
            else:
                d[t] = 1
    return d
def cdiv(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return list(map(int, input().split()))
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a*b) // math.gcd(a, b)

n = ii()
d = ii()
e = ii()

r = n%d
while n >= 5*e:
    n = n - (5*e)
    r = min(r, n%d)
print(r)



import sys
input = sys.stdin.readline


n = int(input())
d = int(input())
e = int(input())

D=d*1
E=e*5

x=n%D

ANS=x

for i in range(x,min(n,x+D*1000)+1,D):
    ANS=min(ANS,i%E)

print(ANS)


def solvea():
    n = int(input())
    d = int(input())
    e = 5 * int(input())
    best = 0
    for enr in range(n // e + 1):
        curr = e * enr
        curr += d * ((n - curr) // d)
        if curr <= n and curr > best:
            best = curr
    print(n - best)

def solveb():
    a = int(input())
    b = int(input())
    n = int(input())
    ans = 0
    for i in range(a + 1):
        for j in range(b + 1):
            if i + j == n:
                ans += 1
    print(ans)


def __starting_point():
    solvea()

__starting_point()

n = int(input())
d = int(input())
e = int(input())
# find nd and ne: ne = 5k, n - nd * d - ne * e min
max_d = n // d #max amount of dollars
max_e = n // e - ((n // e) % 5)
r_min = n
for i in range(0, max_e + 1, 5):
    res = n - i * e
    cur_rub = res - (res // d) * d
    if cur_rub < r_min:
        r_min = cur_rub
print(r_min)

#    ~####~~~#####~~~~####~~~######~~#####~~~#####~~~##~~##
#    ##~~##~~##~~##~~##~~##~~~~~##~~~##~~##~~##~~~~~~##~##
#    ##~~##~~#####~~~######~~~~##~~~~#####~~~####~~~~####
#    ##~~##~~##~~##~~##~~##~~~##~~~~~##~~##~~##~~~~~~##~##
#    ~####~~~##~~##~~##~~##~~######~~#####~~~#####~~~##~~##
import math


class Read:
    @staticmethod
    def int():
        return int(input())

    @staticmethod
    def list(sep=' '):
        return input().split(sep)

    @staticmethod
    def list_int(sep=' '):
        return list(map(int, input().split(sep)))


def solve():
    r = Read.int()
    d = Read.int()
    e = Read.int() * 5

    m = math.inf
    for i in range(r // e + 1):
        t = (r - i * e) % d
        if t < m:
            m = t
        if m == 0:
            print(0)
            return
    print(m)


query_count = 1
# query_count = Read.int()
for j in range(query_count):
    solve()


n = int(input())

d = int(input())
e = int(input())

ans = min(n % d, n%(5*e))

if (d < 5*e):
    T = int(n / (5*e))
    c = 5 * e
    c2 = d
else:
    T = int(n / d)
    c = d
    c2 = 5 * e

for i in range(T + 1):
    ans = min(ans, (n - i * c - c2 * int((n - i * c)/c2)))

print(ans)

n = int(input())
d = int(input())
e = int(input())


mn = 99999999999
while n>=0:
    res = n%d
    if res < mn:
        mn = res
    n = n - 5*e




print(mn)


n=int(input(""))
d=int(input(""))
e=int(input(""))
e*=5
ans=n
for i in range (0,n//d+1) :
   a=(n-d*i)%e
   if a<ans : ans=a
print (ans)