#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define ll long long
#define reado                         \
	;                                 \
	freopen("input.txt", "r", stdin); \
	freopen("output.txt", "w", stdout);
#define bist                 \
	;                        \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define beg(it) \
	;           \
	map<int, int>::iterator it = mp.begin();
#define vll vector<ll>
#define vs vector<string>
#define all(v) v.begin(), v.end()
using namespace std;
const double eps = 1e-9;
const ll mod = 1000000007;
int main()
{
	//reado;
	bist;
	int t;

	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		vi a(n);
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		ll cmin = 1e18;
		for (ll i = 1; i <= n; i++)
		{
			ll c = 0;
			ll last = -1;
			for (int j = 0; j < n; j++)
			{
				if (a[j] == i)
				{
					if (last != j-1)
						c++;
					last = j;
				}
			}
			if (last != n-1)
				c++;
			if (c < cmin && last != -1)
				cmin = c;
		}
		cout << cmin << " ";
	}
}


s = list(input())
try:
    res = s.index('[')
    t = (s.index('[') + 1)
    s = s[t:]
    res += s.index(':')
    s = s[(s.index(':') + 1):][::-1]
    res += s.index(']')
    s = s[(s.index(']') + 1):]
    res += s.index(':')
    s = s[(s.index(':') + 1):]
    res += len(s) - s.count('|')
    print(res)
except ValueError:
    print(-1)


import re
def findBeetween(symb,inp):
    x,y = inp.find(symb[0]), len(inp) - inp[::-1].find(symb[1])
    if x != -1 and y != -1 and x < y-1:
        return inp[x+1:y-1]
    return None
r = input()
x = findBeetween("[]",r)
if x is not None:
    y = findBeetween("::",x)
    if y is not None:
        print(len(re.sub('[^|]', '', y))+4)
    else:
        print(-1)
else:
    print(-1)


import re
def findBeetween(symb,inp):
    x,y = inp.find(symb[0]), len(inp) - inp[::-1].find(symb[1])
    if x != -1 and y < len(inp) and x < y-1:
        return inp[x+1:y-1]
    return None
r = input()
x = findBeetween("[]",r)
if x is not None:
    y = findBeetween("::",x)
    if y is not None:
        print(len(re.sub('[^|]', '', y))+4)
    else:
        print(-1)
else:
    print(-1)


import re
def findBeetween(symb,inp):
    x,y = inp.find(symb[0]), len(inp) - inp[::-1].find(symb[1])
    if x != -1 and y <= len(inp) and x < y-1:
        return inp[x+1:y-1]
    return None
r = input()
x = findBeetween("[]",r)
if x is not None:
    y = findBeetween("::",x)
    if y is not None:
        print(len(re.sub('[^|]', '', y))+4)
    else:
        print(-1)
else:
    print(-1)


s=input()
n=len(s)
if ']' not in s:
	print(-1)
	exit()
else:
	b2=n-1-s[::-1].index(']')
if s.count(':')<2:
	print(-1)
	exit()
else:
	d2=n-1-s[::-1].index(':')
	d1=s.index(':')
if '[' not in s:
	print(-1)
	exit()
else:
	b1=s.index('[')
if b1<d1 and d1<d2 and d2<b2:
	c=0
	for i in range(d1+1,d2):
		if s[i]=='|':
			c+=1
	print(c+4)
else:
	print(-1)

"""
b1=d1=d2=b2=c=0
for i in s:
	if i=='[' and b1==0:
		b1=1
	elif i==':' and b1==1 and d1==0:
		d1=1
	elif i=='|' and d1==1 and d2==0:
		c+=1
	elif i==':' and d1==1:
		d2=1
	elif i==']' and d2==1:
		b2=1
if b2==1:
	print(c+4)
else:
	print(-1)
"""


s=input()
n=len(s)
if ']' not in s:
	print(-1)
	exit()
else:
	b2=n-1-s[::-1].index(']')
if '[' not in s:
	print(-1)
	exit()
else:
	b1=s.index('[')
if s[b1+1:b2].count(':')<2:
	print(-1)
	exit()
else:
	d1=b1+1+s[b1+1:b2].index(':')
	d2=(b2-1-s[b2-1:b1:-1].index(':'))
if b1<d1 and d1<d2 and d2<b2:
	c=0
	for i in range(d1+1,d2):
		if s[i]=='|':
			c+=1
	print(c+4)
else:
	print(-1)


data = list(input())

try:
    data = data[data.index("["):]
    end_index = len(data) - data[::-1].index("]") - 1
    first_colon = data[:end_index].index(":")
    second_colon = len(data[:end_index]) - data[:end_index][::-1].index(":") - 1
except:
    import sys
    print(-1)
    sys.exit()

if first_colon != second_colon:
    print(data[first_colon:second_colon].count('|') + 4)
else:
    print(-1)


data = list(input())
data = data[data.index("["):]

new_string = ["["]
try:
    end_index = len(data) - data[::-1].index("]") - 1
    first_colon = data[:end_index].index(":")
    second_colon = len(data[:end_index]) - data[:end_index][::-1].index(":") - 1
except:
    import sys
    print(-1)
    sys.exit()

if first_colon != second_colon:
    print(data[first_colon:second_colon].count('|') + 4)
else:
    print(-1)


data = list(input())
data = data[data.index("["):]

new_string = ["["]
end_index = len(data) - data[::-1].index("]") - 1
first_colon = data[:end_index].index(":")
second_colon = len(data[:end_index]) - data[:end_index][::-1].index(":") - 1

if first_colon != second_colon:
    print(data[first_colon:second_colon].count('|') + 4)
else:
    print(-1)


a = input()
s= list(a)
q=["|"]
count=0
flag=1
while s[0]!="[":
    s.remove(s[0])
    if len(s)==0:
        flag=0
        break
if len(s)>=3:
    while s[1]!=":":
        s.remove(s[1])
        if len(s)==1 or len(s)==0:
            flag=0
            break

    while s[len(s)-1]!="]":
        s.remove(s[len(s)-1])
        if len(s)==0 or len(s)==1 or len(s) ==2 or len(s)==3:
            flag=0
            break

    while s[len(s)-2]!=":":
        s.remove(s[len(s)-2])
        if len(s)==0 or len(s)==1 or len(s) ==2 or len(s)==3 or len(s)==4:
            flag=0
            break
else:
    flag=0
if flag==0:
    print(-1)
elif s.count(":")<2:
    print(-1)
else:
    for i in s:
        if i=="|":
            count+=1
    print(4+count)


a = input()
s= list(a)
q=["|"]
count=0
flag=1
while s[0]!="[":
    s.remove(s[0])
    if len(s)==0:
        flag=0
        break
if len(s)>=3:
    while s[1]!=":":
        s.remove(s[1])
        if len(s)==1 or len(s)==0:
            flag=0
            break

    while s[len(s)-1]!="]":
        s.remove(s[len(s)-1])
        if len(s)==0 or len(s)==1 or len(s) ==2:
            flag=0
            break

    while s[len(s)-2]!=":":
        s.remove(s[len(s)-2])
        if len(s)==0 or len(s)==1 or len(s) ==2 or len(s)==3:
            flag=0
            break
else:
    flag=0
if flag==0:
    print(-1)
elif s.count(":")<2:
    print(-1)
else:
    for i in s:
        if i=="|":
            count+=1
    print(4+count)


a = input()
s= list(a)
q=["[",":","]","|"]

flag=1
while s[0]!="[":
    s.remove(s[0])
    if len(s)==0:
        flag=0
        break
if len(s)>=3:
    while s[1]!=":":
        s.remove(s[1])
        if len(s)==1 or len(s)==0:
            flag=0
            break

    while s[len(s)-1]!="]":
        s.remove(s[len(s)-1])
        if len(s)==0 or len(s)==1 or len(s) ==2:
            flag=0
            break

    while s[len(s)-2]!=":":
        s.remove(s[len(s)-2])
        if len(s)==0 or len(s)==1 or len(s) ==2 or len(s)==3:
            flag=0
            break
else:
    flag=0
if flag==0:
    print(-1)
elif s.count(":")<2:
    print(-1)
else:
    for i in s:
        if i not in q:
            s.remove(i)
        if i=="[" and s.index(i)>0:
            s.remove(i)
        if i=="]" and s.index(i)<len(s)-1:
            s.remove("]")
    print(len(s))


def main(s):
    res = -1
    if '[' in s:
        a = s.index('[')
        if ']' in s[a:]:
            b = s[a:].rfind(']') + a
            if ':' in s[a:b]:
                c = s[a:b].index(':') + a + 1
                if ':' in s[c:b]:
                    d = s[c:b].rfind(':') + c
                    res = 4 + s[c:d].count('|')
    return res

# assert(main('[::]') == 4)
# assert(main('jdkfjg[:fsdjf:fjd]fsdkj') == 4)
# assert(main('j||:||[dk[fjg[:fs||djf:fjd]fsdkj') == 6)
# assert(main('[:]') == -1)
# assert(main('[:|:]') == 5)
# assert(main('[:|:]|:]') == 6)
if __name__ == '__main__':
    print(main(input()))


s=input()
if '[' not in s: print(-1)
else:
    ind=s.find('[')
    if ']' not in s[ind+1:] or s[ind+1:].count(':')<2: print(-1)
    else:
        cnt=0
        cb=s.rfind(']')
        ind=s[ind+1:cb].find(':')
        if ind<0: print(-1)
        else:
            sc=cb-1
            while s[sc]!=':': sc-=1
            if sc==ind: print(-1)
            else:
                ind+=1
                while ind<sc:
                    if s[ind]=='|': cnt+=1
                    ind+=1
                print(cnt+4)


s=input()
ob=s.find('[')
cb=s.rfind(']')
fc=s[ob+1:cb].find(':')
sc=s[ob+1:cb].rfind(':')
if ob>cb or fc==sc: print(-1); exit()
print(4+s[fc:sc].count('|'))


s=input()
ob=s.find('[')
cb=s.rfind(']')
fc=s[ob:cb].find(':')
sc=s[ob:cb].rfind(':')
if ob>cb or fc==sc: print(-1)
else: print(4+s[ob+fc:ob+sc].count('|'))


s=input()
ob=s.find('[')
cb=s.rfind(']')
fc=s[ob+1:cb].find(':')
sc=s[ob+1:cb].rfind(':')
if ob>cb or fc==sc: print(-1); exit()
print(4+s[ob+fc:ob+sc].count('|'))


s=input()
ob=s.find('[')
cb=s.rfind(']')
fc=s[ob+1:cb].find(':')
sc=s[ob+1:cb].rfind(':')
if ob>cb or fc==sc: print(-1); exit()
print(4+s[fc+ob:sc+cb].count('|'))


s=list(input())
if not '[' in s or not ']' in s:
    print(-1)
else:
    a=s.index('[')
    s.reverse()
    b=len(s)-s.index(']')-1
    s.reverse()
    s=s[a:b+1]
    if s.count(':')<2:
        print(-1)
    else:
        a=s.index(':')
        s.reverse()
        b=len(s)-s.index(':')-1
        s.reverse()
        d=s[a:b+1]
        print(d.count('|')+4)


s=list(input())
if not '[' in s or not ']' in s:
    print(-1)
a=s.index('[')
s.reverse()
b=len(s)-s.index(']')-1
s.reverse()
s=s[a:b+1]
if s.count(':')<2:
    print(-1)
else:
    a=s.index(':')
    s.reverse()
    b=len(s)-s.index(':')-1
    s.reverse()
    d=s[a:b+1]
    print(d.count('|')+4)


s=list(input())
if not '[' in s or not ']' in s:
    print(-1)
a=s.index('[')
s.reverse()
b=len(s)-s.index(']')-1
s.reverse()
d=s[a:b+1]
while d[1]!=':':
    d.pop(1)
while d[-2]!=':':
    d.pop(-2)
if len(d)<4:
    print(-1)
else:
    f=0
    for i in d[2:-2]:
        if i=='|':
            f+=1
    print(f+4)


import sys
a = input()
a = list(a)
h = []
f = []
s = 0
p = 0
b = a.copy()
flag1 = False
flag2 = False
for i in range(len(a)):
    if a[i] == '[':
        h.append(i)
        flag1 = True
    if a[i] == ']':
        s = i
        flag2 = True
h = h[0]
if flag1 == False:
    print(-1)
    sys.exit()
if flag2 == False:
    print(-1)
    sys.exit()
a = a[h+1:s]
if a.count(':') < 2:
    print(-1)
    sys.exit()
for i in range(len(a)):
    if a[i] == ':':
        f.append(i)
a = a[f[0]+1:f[-1]]
ans = 4 + a.count('|')
print(ans)


import sys
a = input()
a = list(a)
h = []
f = []
s = 0
p = 0
b = a.copy()
flag1 = False
flag2 = False
for i in range(len(a)):
    if a[i] == '[':
        h.append(i)
        flag1 = True
    if a[i] == ']':
        s = i
        flag2 = True
if flag1 == False:
    print(-1)
    sys.exit()
if flag2 == False:
    print(-1)
    sys.exit()
h = h[0]
a = a[h+1:s]
if a.count(':') < 2:
    print(-1)
    sys.exit()
for i in range(len(a)):
    if a[i] == ':':
        f.append(i)
a = a[f[0]+1:f[-1]]
ans = 4 + a.count('|')
print(ans)


import fileinput as fs

def printSol(inputLine):
    foundFirst = False
    foundSecond = False
    colon = False
    res = -1
    notCountedAfterColon = 0
    possibleRes = res
    for i in range(0, len(inputLine)):
            if not foundFirst and inputLine[i] == '[':
                foundFirst = not foundFirst
                continue
            if foundFirst and not foundSecond and inputLine[i] == ':':
                foundSecond = not foundSecond
                res = 2
                continue
            if foundFirst and foundSecond:
                if not colon and inputLine[i] == '|':
                    res = res + 1
                    continue
                if colon and inputLine[i] == '|':
                    notCountedAfterColon = notCountedAfterColon + 1
                if not colon and inputLine[i] == ':':
                    colon = not colon
                    notCountedAfterColon = 0
                    continue
                if colon and inputLine[i] == ':':
                    res = res + notCountedAfterColon
                    continue
                if colon and inputLine[i] == ']':
                    colon = not colon
                    possibleRes = res + 2
    print(possibleRes)

if __name__ == "__main__":
    for line in fs.input():
        printSol(line)
        break


import fileinput as fs

def printSol(inputLine):
    foundFirst = False
    foundSecond = False
    colon = False
    res = -1
    possibleRes = res
    for i in range(0, len(inputLine)):
            if not foundFirst and inputLine[i] == '[':
                foundFirst = not foundFirst
                continue
            if foundFirst and not foundSecond and inputLine[i] == ':':
                foundSecond = not foundSecond
                res = 2
                continue
            if foundFirst and foundSecond:
                if not colon and inputLine[i] == '|':
                    res = res + 1
                    continue
                if not colon and inputLine[i] == ':':
                    colon = not colon
                    continue
                if colon and inputLine[i] == ']':
                    colon = not colon
                    possibleRes = res + 2
    print(possibleRes)

if __name__ == "__main__":
    for line in fs.input():
        printSol(line)
        break


import fileinput as fs

def printSol(inputLine):
    foundFirst = False
    foundSecond = False
    res = -1
    possibleRes = res
    confirmedRes = res
    for i in range(0, len(inputLine)):
            if not foundFirst and inputLine[i] == '[':
                foundFirst = not foundFirst
                continue
            if foundFirst and not foundSecond and inputLine[i] == ':':
                foundSecond = not foundSecond
                res = 2
                continue
            if foundFirst and foundSecond:
                if inputLine[i] == '|':
                    res = res + 1
                    continue
                if inputLine[i] == ':':
                    possibleRes = res + 2
                    continue
                if inputLine[i] == ']':
                    confirmedRes = possibleRes
    print(confirmedRes)

if __name__ == "__main__":
    for line in fs.input():
        printSol(line)
        break


s=input()
n=len(s)
ans=0
count=0
for x in range(n):
	if count==0:
		if s[x]=='[':
			count=1
		else:
			ans+=1
	elif count==1:
		if s[x]==':':
			count=2
		else:
			ans+=1
	elif count ==2:
		if s[x]==':':
			count=3
		elif s[x]!='|':
			ans+=1
	elif count==3:
		if s[x]==']':
			count=4
		else:
			ans+=1
	elif count==4:
		ans+=1
if count==4:
	print(n-ans)
else:
	print(-1)


s=input()
count=0
i=0
flag=0
for x in range(len(s)):
	if s[x]=='[':
		s=s[x+1:]
		flag=1
		break;
if flag==1:
	flag=0
	for x in range(len(s)):
		if s[x]==':':
			s=s[x+1:]
			flag=1
			break;
	if flag==1:
		flag=0
		for x in range(len(s)-1,-1,-1):
			if s[x]==']':
				s=s[:x]
				flag=1
				break;
		if flag==1:
			flag=0
			for x in range(len(s)-1,-1,-1):
				if s[x]==':':
					s=s[:x]
					flag=1
					break;
			if flag==1:
				for x in range(len(s)):
					if(s[x]=='|'):
						count+=1
			else:
				print(-1)
		else:
			print(-1)
	else:
		print(-1)
else:
	print(-1)
if flag==1:
	print(count+4)


s=input()
n=len(s)
ans=0
count=0
for x in range(n):
	if count==0:
		if s[x]=='[':
			count=1
		else:
			ans+=1
	elif count==1:
		if s[x]==':':
			count=2
		else:
			ans+=1
	elif count ==2:
		if s[x]==':':
			count=3
		elif s[x]!='|':
			ans+=1
	elif count==3:
		if s[x]==']':
			count=4
		else:
			ans+=1
	elif count==4:
		ans+=1
if count==4:
	print(ans)
else:
	print(-1)


"""
https://codeforces.com/problemset/problem/1159/B
"""

l = list(input())

open_bracket= False
start= False
pos_close = False
finished = False

num = 0

res = []
finish = []
first = True

for char in l:
    if first:
        if not open_bracket and char == '[':
            open_bracket= True
            continue
        if open_bracket and char == ':':
            start = True
            first= False
            continue
    if not start:
        continue
    if char == '|': num+=1
    if char == ':':
        pos_close = True
        res.append(num)
    if pos_close and char =="]":
        finished = True
        finish.append(res[-1])
if finished:
    print(finish[-1]+4)
else:
    print(-1)


accord = input()

open_bracket = accord.find("[")
accord=accord[open_bracket+1:]
open_colon = accord.find(":")
accord = accord[open_colon+1:]
close_bracket = accord.rfind("]")
close_colon = accord[:close_bracket].rfind(":")

if open_bracket == -1 or open_colon == -1 or close_bracket == -1 or close_colon == -1:
    print(-1)
else:
    res = accord[:close_colon].count("|")+4
    print(res)


ind = [-1] * 4
need = 1
arr = input()
n = len(arr)
for i in range(n):
    if need == 1:
        if arr[i] == '[':
            ind[0] = i
            need += 1
    elif need == 2:
        if arr[i] == ':':
            ind[1] = i
            break
need = 4
for i in range(n-1, -1, -1):
    if need == 4:
        if arr[i] == ']':
            ind[3] = i
            need -= 1
    elif need == 3:
        if arr[i] == ':':
            ind[2] = i
            break
if ind[1] == ind[2] or ind != sorted(ind):
    print(-1)
    exit()
for i in range(4):
    if ind[i] == -1:
        print(-1)
        exit()
res = 4 + (ind[2] - 1 - ind[1])
for i in range(ind[1]+1, ind[2]):
    if arr[i] != '|':
        res -= 1
print(res)


ind = [-1] * 4
need = 1
arr = input()
n = len(arr)
for i in range(n):
    if need == 1:
        if arr[i] == '[':
            ind[0] = i
            need += 1
    elif need == 2:
        if arr[i] == ':':
            ind[1] = i
            break
need = 4
for i in range(n-1, -1, -1):
    if need == 4:
        if arr[i] == ']':
            ind[3] = i
            need -= 1
    elif need == 3:
        if arr[i] == ':':
            ind[2] = i
            break
if ind[1] == ind[2] or ind[0] > ind[3]:
    print(-1)
    exit()
for i in range(4):
    if ind[i] == -1:
        print(-1)
        exit()
res = 4 + (ind[2] - 1 - ind[1])
for i in range(ind[1]+1, ind[2]):
    if arr[i] != '|':
        res -= 1
print(res)


ind = [-1] * 4
need = 1
arr = input()
n = len(arr)
for i in range(n):
    if need == 1:
        if arr[i] == '[':
            ind[0] = i
            need += 1
    elif need == 2:
        if arr[i] == ':':
            ind[1] = i
            break
need = 4
for i in range(n-1, -1, -1):
    if need == 4:
        if arr[i] == ']':
            ind[3] = i
            need -= 1
    elif need == 3:
        if arr[i] == ':':
            ind[2] = i
            break
if ind[1] == ind[2]:
    print(-1)
    exit()
for i in range(4):
    if ind[i] == -1:
        print(-1)
        exit()
res = 4 + (ind[2] - 1 - ind[1])
for i in range(ind[1]+1, ind[2]):
    if arr[i] != '|':
        res -= 1
print(res)


ind = [-1] * 4
need = 1
arr = input()
n = len(arr)
for i in range(n):
    if need == 1:
        if arr[i] == '[':
            ind[0] = i
            need += 1
    elif need == 2:
        if arr[i] == ':':
            ind[1] = i
            break
need = 4
for i in range(n-1, -1, -1):
    if need == 4:
        if arr[i] == ']':
            ind[3] = i
            need -= 1
    elif need == 3:
        if arr[i] == ':':
            ind[2] = i
            break
if ind[1] == ind[2]:
    print(-1)
    exit()
for i in range(4):
    if ind[i] == -1:
        print(-1)
        exit()
res = 4 + (ind[2] - 1 - ind[1])
for i in range(ind[1]+1, ind[2]):
    if ord(arr[i]) in range(97, 123):
        res -= 1
print(res)


import re
def sol():
    pattern = "\[.*\]"
    s = input()
    reg = re.compile(pattern)
    result = reg.search(s)
    if result == None:
        return -1
    pattern2 = ":.*:"
    reg = re.compile(pattern2)
    result2 = reg.search(result.group(0))
    if result2 == None:
        return -1
    res = 4
    for i in result2.group(0):
        if i == '|':
            res += 1
    return res

print(sol())


import re
pattern = "\[.*\]"
s = input()
reg = re.compile(pattern)
#result = reg.search(s)
print(result.group(0))
res = -1
l = 0
d = 0
for i in result.group(0):
    if d == 1:
        if i == '|':
            l += 1
        elif i == ':':
            l += 1
            res = max(res, l)
            l = 1
    else:
        d = 1
        l = 1

if(res == -1):
    print(-1)
else:
    print(len(s) - res - 2)


import re
pattern = "\[.*\]"
s = input()
reg = re.compile(pattern)
result = reg.search(s)
#print(result.group(0))
res = -1
l = 0
d = 0
for i in result.group(0):
    if d == 1:
        if i == '|':
            l += 1
        elif i == ':':
            l += 1
            res = max(res, l)
            l = 1
    elif i == ':':
        d = 1
        l = 1

if(res == -1):
    print(-1)
else:
    print(len(s) - res - 2)


import re
def sol():
    pattern = "\[.*\]"
    s = input()
    reg = re.compile(pattern)
    result = reg.search(s)
    if result == None:
        return -1
    pattern2 = ":.*:"
    reg = re.compile(pattern2)
    result2 = reg.search(result.group(0))
    if result2 == None:
        return -1
    res = 4
    for i in result2.group(0):
        if i == '|':
            res += 1
    return len(s) - res

print(sol())


import re
s = input()
si = s[::-1]
def sol():
    res = 4
    l = s.find('[')
    if l == -1:
        return -1
    l = s.find(':', l + 1)
    if l == -1:
        return -1
    r = si.find(']')
    if r == -1:
        return -1
    r = si.find(':', r + 1)
    if r == -1:
        return -1
    r = len(s) - r
    for i in range(l, r):
        if s[i] == '|':
            res += 1
    return res
print(sol())


import re
s = input()
def sol():
    reg = re.compile("\[.*\]")
    result = reg.search(s)
    if result == None:
        return -1
    reg = re.compile(":.*:")
    result2 = reg.search(result.group(0))
    if result2 == None:
        return -1
    return 4 + result2.group(0).count('|')
print(sol())


import re
pattern = "\[.*\]"
s = input()
reg = re.compile(pattern)
result = reg.search(s)
res = -1
l = 0
d = 0
for i in result.group(0):
    if d == 1:
        if i == '|':
            l += 1
        elif i == ':':
            l += 1
            res = max(res, l)
            l = 1
        else:
            l = 0
            d = 0
    elif i == ':':
        d = 1
        l = 1

if(res == -1):
    print(-1)
else:
    print(len(s) - res - 2)


import re
s = input()
si = s[::-1]
def sol():
    res = 4
    l = s.find('[')
    if l == -1:
        return -1
    l = s.find(':', l + 1)
    if l == -1:
        return -1
    r = si.find(']')
    if r == -1:
        return -1
    r = si.find(':', r + 1)
    if r == -1:
        return -1
    r = len(s) - r
    if r - 1 <= l:
        return -1
    for i in range(l, r):
        if s[i] == '|':
            res += 1
    return res
print(sol())


import re
s = input()
si = s[::-1]
def sol():
    res = 4
    l = s.find('[')
    if l == -1:
        return -1
    l = s.find(':', l + 1)
    if l == -1:
        return -1
    r = si.find(']')
    if r == -1:
        return -1
    r = si.find(':', r + 1)
    if r == -1:
        return -1
    r = len(s) - r
    if r - 1 == l:
        return -1
    for i in range(l, r):
        if s[i] == '|':
            res += 1
    return res
print(sol())


import re
pattern = "\[.*\]"
s = input()
reg = re.compile(pattern)
result = reg.search(s)
#print(result.group(0))
res = -1
l = 0
d = 0
for i in result.group(0):
    if i == ':' and d == 0:
        d = 1
        l = 1
    elif i == '|' and d == 1:
        l += 1
    elif i == ':' and d == 1:
        d = 0
        l += 1
        res = max(res, l)
        l = 0
if(res == -1):
    print(-1)
else:
    print(len(s) - res - 2)


import re
pattern = "\[.*\]"
s = input()
reg = re.compile(pattern)
result = reg.search(s)
#print(result.group(0))
res = -1
l = 0
d = 0
for i in result.group(0):
    if d == 1:
        if i == '|':
            l += 1
        elif i == ':':
            l += 1
            res = max(res, l)
            l = 1
    else:
        d = 1
        l = 1

if(res == -1):
    print(-1)
else:
    print(len(s) - res - 2)


n=input()
max = -1
firstColon = -1
lastColon = -1
openBracket = -1
closeBracket = -1
for i in range(len(n) - 1, -1, -1):
    if n[i] == ']':
        closeBracket = i
        break
for i in range(len(n)):
    if openBracket == -1 and n[i] == '[':
        openBracket = i
    if firstColon == -1 and n[i] == ':' and openBracket != -1 and i < closeBracket:
        firstColon = i
    if n[i] == ':' and openBracket != -1 and i < closeBracket:
        lastColon = i
size = 0
for i in range(firstColon, lastColon):
    if n[i] == '|':
        size += 1
if openBracket != -1 and closeBracket != -1 and firstColon != lastColon and openBracket < closeBracket:
    max = size + 4
print(max)


n=input()
max = -1
firstColon = -1
lastColon = -1
openBracket = -1
closeBracket = -1
for i in range(len(n)):
    if openBracket == -1 and n[i] == '[':
        openBracket = i
    if n[i] == ']':
        closeBracket = i
    if firstColon == -1 and n[i] == ':' and openBracket != -1:
        firstColon = i
    if n[i] == ':' and openBracket != -1:
        lastColon = i
size = 0
for i in range(firstColon, lastColon):
    if n[i] == '|':
        size += 1
if openBracket != -1 and closeBracket != -1 and firstColon != lastColon and openBracket < closeBracket:
    max = size + 4
print(max)


import sys
import math

def read_int():
	return int(input().strip())

def read_int_list():
	return list(map(int,input().strip().split()))

def read_string():
	return input().strip()

def read_string_list(delim=" "):
	return input().strip().split(delim)

###### Author : Samir Vyas #######
###### Write Code Below    #######

def find(s,startIndex,char,begin):
	if begin:
		head = startIndex
		while head < len(s):
			if s[head] == char:
				return head
			head += 1
		return -1

	if not begin:
		tail = startIndex
		while tail >= 0:
			if s[tail] == char:
				return tail
			tail -= 1
		return -1

_s = read_string()

s = ""

for a in _s:
	if a in ["[",":","]","|"]:
		s += a

first_open = find(s,0,"[",True)
last_open = find(s,len(s)-1,"]",False)
first_colon = find(s,first_open,":",True)
last_colon = find(s,last_open,":",False)

if not(first_open < first_colon < last_colon < last_open):
	print(-1)
	sys.exit()

num_ver = 0

for i in range(first_colon,last_colon):
	if s[i] == "|":
		num_ver += 1

print(len(_s)-num_ver-4)


import sys
import math

def read_int():
	return int(input().strip())

def read_int_list():
	return list(map(int,input().strip().split()))

def read_string():
	return input().strip()

def read_string_list(delim=" "):
	return input().strip().split(delim)

###### Author : Samir Vyas #######
###### Write Code Below    #######

def find(s,startIndex,char,begin):
	if begin:
		head = startIndex
		while head < len(s):
			if s[head] == char:
				return head
			head += 1
		return -1

	if not begin:
		tail = startIndex
		while tail >= 0:
			if s[tail] == char:
				return tail
			tail -= 1
		return -1

_s = read_string()

s = ""

for a in _s:
	if a in ["[",":","]","|"]:
		s += a

first_open = find(s,0,"[",True)
last_open = find(s,len(s)-1,"]",False)
first_colon = find(s,first_open,":",True)
last_colon = find(s,last_open,":",False)

if not (first_open < first_colon < last_colon < last_open):
	print(-1)
	sys.exit()

num_ver = 0

for i in range(first_colon,last_colon):
	if s[i] == "|":
		num_ver += 1

print(num_ver+4)


import sys
import math

def read_int():
	return int(input().strip())

def read_int_list():
	return list(map(int,input().strip().split()))

def read_string():
	return input().strip()

def read_string_list(delim=" "):
	return input().strip().split(delim)

###### Author : Samir Vyas #######
###### Write Code Below    #######

s = read_string()

first = s.find("[",0,len(s))
second = s.find(":",first,len(s))
fourth = s.rfind("]")
third = s.rfind(":",second,len(s))

if first == -1 or second == -1 or third == -1 or fourth == -1:
	print(-1)
	sys.exit()

if first < second < third < fourth:
	counter = 0
	for i in range(second,third):
		if s[i] == "|":
			counter += 1

	print(counter+4)
else:
	print(-1)


import sys
import math

def read_int():
	return int(input().strip())

def read_int_list():
	return list(map(int,input().strip().split()))

def read_string():
	return input().strip()

def read_string_list(delim=" "):
	return input().strip().split(delim)

###### Author : Samir Vyas #######
###### Write Code Below    #######

s = read_string()

first = s.find("[",0,len(s))
second = s.find(":",first,len(s))
fourth = s.rfind("]")
third = s.rfind(":",second,fourth)

if first == -1 or second == -1 or third == -1 or fourth == -1:
	print(-1)
	sys.exit()

if first < second < third < fourth:
	counter = 0
	for i in range(second,third):
		if s[i] == "|":
			counter += 1

	print(counter+4)
else:
	print(-1)


s = input()
i = 0
N = len(s)
while i < N and s[i] != "[":
    i += 1
while i < N and s[i] != ":":
    i += 1

j = N - 1
while j >= 0 and s[j] != "]":
    j -= 1
while j >= 0 and s[j] != ":":
    j -= 1

if i >= j:
    print(-1)
else:
    num = i + N - j - 4
    for k in range(i, j):
        if s[i] != "|":
            num += 1

    print(num)


s = input()
i = 0
N = len(s)
while i < N and s[i] != "[":
    i += 1
while i < N and s[i] != ":":
    i += 1

j = N - 1
while j >= 0 and s[j] != "]":
    j -= 1
while j >= 0 and s[j] != ":":
    j -= 1

if i >= j:
    print(-1)
else:
    num = 4
    for k in range(i, j):
        if s[k] == "|":
            num += 1

    print(num)


s = input()
i = 0
N = len(s)
while i < N and s[i] != "[":
    i += 1
while i < N and s[i] != ":":
    i += 1

j = N - 1
while j >= 0 and s[j] != "]":
    j -= 1
while j >= 0 and s[j] != ":":
    j -= 1

if i >= j:
    print(-1)
else:
    num = 4
    for k in range(i, j):
        if s[i] == "|":
            num += 1

    print(num)


accords = input()
lft = accords.find("[")
rt = accords.rfind("]")
if lft < rt and lft != -1 and rt != -1:
    piano = accords[lft : rt + 1]
    lft = piano.find(":")
    rt = piano.rfind(":")
    if lft != -1 and lft != rt:
        count = piano[lft: rt + 1].count("|")
        print(4 + count)
    else:
        print(-1)
else:
    print(-1)


accords = input()
lft = accords.find("[")
rt = accords.rfind("]")
count = 0
if lft < rt and lft != -1 and rt != -1:
    piano = accords[lft : rt + 1]
else:
    print(-1)
lft = piano.find(":")
rt = piano.rfind(":")
if lft != -1 and lft != rt:
    count = piano[lft: rt + 1].count("|")
    print(4 + count)
else:
    print(-1)


accords = input()
lft = accords.find("[")
rt = accords.rfind("]")
count = 0
if lft < rt:
    piano = accords[lft : rt + 1]
else:
    print(-1)
lft = piano.find(":")
rt = piano.rfind(":")
if lft != -1 and lft != rt:
    organ = piano[lft: rt + 1]
    for char in organ:
        if char == "|":
            count += 1
    print(4 + count)
else:
    print(-1)


accords = input()
lft = accords.find("[")
rt = accords.rfind("]")
count = 0
if lft < rt:
    piano = accords[lft : rt + 1]
else:
    print(-1)
lft = piano.find(":")
rt = piano.rfind(":")
if lft != -1 and lft != rt:
    count = piano[lft: rt + 1].count("|")
    print(4 + count)
else:
    print(-1)


import sys

s = input()

left = s.find("[")
right = s.rfind("]")

if left < 0 or right < 0:
    print(-1)
    sys.exit()

s = s[left : right + 1]

left = s.find(":")
right = s.rfind(":")

if left < 0 or right < 0 or left == right:
    print(-1)
    sys.exit()

s = s[left : right + 1]

print(s.count("|") + 4)


import sys

s = input()

left = s.find("[")
right = s.rfind("]")

if left < 0 or right < 0:
    print(-1)
    sys.exit()

left = s.find(":", left + 1, right)
right = s.rfind(":", left + 1, right)

if left < 0 or right < 0 or left == right:
    print(-1)
    sys.exit()

print(4 + s.count("|", left + 1, right))


def main():
	s = input()
	s = list(s)

	l = 0
	max = 0
	i = 0
	pair = False

	while i < len(s) and s[i] != '[' :
		i += 1
	i += 1
	while i < len(s) and s[i] != ':':
		i += 1
	i += 1
	while i < len(s) and s[i] != ']':
		if s[i] == '|':
			l += 1
		elif s[i] == ':':
			pair = True
			if max < l:
				max = l
			l = 0
		i += 1

	if pair:
		print(max + 4)
	else:
		print(-1)
	# print(s)
	# final = []
	# for i in range(len(s)):
	# 	if s[i] != 0:
	# 		final.append(s[i])

	# # print(final)
	# if len(final) >= 4 and final[0] == '[' and final[1] == ':' and final[-2] == ':' and final[-1] == ']':
	# 	print(len(final))
	# else:
	# 	print(-1)

if __name__ == "__main__":
	main()


def main():
	s = input()
	s = list(s)

	l = 0
	i = 0
	pair = False

	while i < len(s) and s[i] != '[' :
		i += 1
	i += 1
	while i < len(s) and s[i] != ':':
		i += 1

	j = len(s) - 1
	while j > i and s[j] != ']':
		j -= 1
	j -= 1

	while j > i and s[j] != ':':
		j -= 1

	for k in range(i, j):
		if s[k] == '|':
			l += 1

	if j <= i:
		print(-1)
	else:
		print(l+4)

if __name__ == "__main__":
	main()


s = input()
lb = s.find("[")
rb = s.rfind("]")
s = s[lb+1:rb]
if s == "":
  print(-1)
else:
  lc = s.find(":")
  rc = s.rfind(":")
  if s[lc+1:rc] == "":
    print(-1)
  else:
    if s[lc+1:rc].count("|") == 0:
      print(-1)
    else:
      print(4+s[lc+1:rc].count("|"))


s = input()
lb = s.find("[")
rb = s.rfind("]")
s = s[lb+1:rb]
if s == "":
  print(-1)
else:
  lc = s.find(":")
  rc = s.rfind(":")
  if s[lc+1:rc] == "":
    print(-1)
  else:
    print(4+s[lc+1:rc].count("|"))


s = input()
lb = s.find("[")
rb = s.rfind("]")
s = s[lb+1:rb]
if s == "" or lb == -1 or rb == -1:
  print(-1)
else:
  lc = s.find(":")
  rc = s.rfind(":")
  if lc == rc or:
    print(-1)
  else:
    print(4+s[lc+1:rc].count("|"))


s = input()
lb = s.find("[")
rb = s.rfind("]")
s = s[lb+1:rb]
if s == "":
  print(-1)
else:
  lc = s.find(":")
  rc = s.rfind(":")
  if lc == rc:
    print(-1)
  else:
    print(4+s[lc+1:rc].count("|"))


s = input()
lb = s.find("[")
rb = s.rfind("]")
s = s[lb+1:rb]
if s == "":
  print(-1)
else:
  lc = s.find(":")
  rc = s.rfind(":")
  print(4+s[lc+1:rc].count("|"))


s = input()
lb = s.find("[")
rb = s.rfind("]")
s = s[lb:rb+1]
if s == "":
  print(-1)
else:
  lc = s.find(":")
  rc = s.rfind(":")
  if s[lc:rc+1] == "":
    print(-1)
  else:
    print(4+s[lc:rc+1].count("|"))


s = input()
lb = s.find("[")
rb = s.rfind("]")
s = s[lb+1:rb]
if s == "" or lb == -1 or rb == -1:
  print(-1)
else:
  lc = s.find(":")
  rc = s.rfind(":")
  if lc == rc:
    print(-1)
  else:
    print(4+s[lc+1:rc].count("|"))


s = input()
lb = s.find("[")
rb = s.find("]")
s = s[lb:rb+1]
if s == "":
  print(-1)
else:
  lc = s.find(":")
  rc = s.find(":")
  if s[lc:rc+1] == "":
    print(-1)
  else:
    print(4+s[lc:rc+1].count("|"))


s = list(input())

start, end = -1, -1
for i in range(len(s)):
	if(s[i] == '['):
		start = i
		break
for i in range(len(s) - 1, -1, -1):
	if(s[i] == ']'):
		end = i
		break

count = 2
ma = 0
for i in range(start + 1, end):
	if(s[i] == ':' and count == 2):
		count += 1
	elif(s[i] == '|' and count > 2):
		count += 1
	elif(s[i] == ':' and count > 2):
		count += 1
		if(count > ma):
			ma = count
		count -= 1

if(ma < 4 or start == -1 or end == -1):
	print(-1)
else:
	print(ma)


s = list(input())
a = []

count = 0
b = False
c = False
k = []
for i in range(len(s)):
	if(s[i] == '['):
		a.append(s[i])
		b = True
	elif(s[i] == ']' and len(a) > 0 and b == True and c == False):
		a.pop()
		b = False
	elif(s[i] == ':' and count == 0 and b == True and c == False):
		a.append(s[i])
		count = 1
		c = True
	elif(s[i] == ':' and count == 1 and b == True and c == True):
		a.pop()
		count = 0
		c = False
	elif(s[i] == '|' and count == 1 and b == True and c == True):
		k.append(s[i])
	#print(a)

if(len(a) > 0):
	print(-1)
else:
	print(len(k) + 4)


s = list(input())

start, end = 0, 0
for i in range(len(s)):
	if(s[i] == '['):
		start = i
		break
for i in range(len(s) - 1, -1, -1):
	if(s[i] == ']'):
		end = i
		break

count = 2
ma = 0
for i in range(start + 1, end):
	if(s[i] == ':' and count == 2):
		count += 1
	elif(s[i] == '|' and count > 2):
		count += 1
	elif(s[i] == ':' and count > 2):
		count += 1
		if(count > ma):
			ma = count
		count -= 1

if(ma >= 4):
	print(ma)
else:
	print(-1)


s = list(input())
a = []

count = 0
b = False
c = False
k = []
for i in range(len(s)):
	if(s[i] == '['):
		a.append(s[i])
		b = True
	elif(s[i] == ']' and len(a) > 0):
		a.pop()
		b = False
	elif(s[i] == ':' and count == 0 and b == True):
		a.append(s[i])
		count = 1
		c = True
	elif(s[i] == ':' and count == 1 and b == True):
		a.pop()
		count = 0
		c = False
	elif(s[i] == '|' and count == 1 and b == True and c == True):
		k.append(s[i])
	#print(a)

if(len(a) > 0):
	print(-1)
else:
	print(len(k) + 4)


s = list(input())

start, end = -1, -1
for i in range(len(s)):
	if(s[i] == '['):
		start = i
		break
for i in range(len(s) - 1, -1, -1):
	if(s[i] == ']'):
		end = i
		break

count = 2
ma = 0
for i in range(start + 1, end):
	if(s[i] == ':' and count == 2):
		count += 1
	elif(s[i] == '|' and count > 2):
		count += 1
	elif(s[i] == ':' and count > 2):
		count += 1
		if(count > ma):
			ma = count
		count -= 1

if(ma >= 4 or start == -1 or end == -1):
	print(ma)
else:
	print(-1)


s = input()
a, b, c, d = s.find('['), s.find(':'), s.rfind(':'), s.rfind(']')
if a == -1 or b == -1 or c == -1 or d == -1 or b == c:
    print(-1)
    exit(0)

cnt = 0
for i in range(b, c + 1):
    cnt += (s[i] == '|')

print(cnt + 4)


s = input()
a, b, c, d = s.find('['), s.find(':'), s.rfind(':'), s.rfind(']')
if a == -1 or b == -1 or c == -1 or d == -1 or b == c:
    print(-1)
    exit(0)

if a < b < c < d:
    cnt = 0
    for i in range(b, c + 1):
        cnt += (s[i] == '|')

    print(cnt + 4)


s = input()
a = s.find('[')
if a == -1:
    print(a)
    exit(0)
b = s.find(':', a)
if b == -1:
    print(b)
    exit(0)

c = s.rfind(']', b)
if c == -1:
    print(c)
    exit(0)

d = s.rfind(':', b + 1, c)
if d == -1:
    print(d)
    exit(0)

cnt = 0
for i in range(b, d):
    cnt += (s[i] == '|')
#print(a, b, d, c)
print(cnt + 4)


s = input()
a, b, c, d = s.find('['), s.find(':'), s.rfind(':'), s.rfind(']')
if a == -1 or b == -1 or c == -1 or d == -1 or b == c:
    print(-1)
    exit(0)

if a < b < c < d:
    cnt = 0
    for i in range(b, c + 1):
        cnt += (s[i] == '|')
    print(cnt + 4)
else:
    print(-1)


s = input()
a = s.find('[')
if a == -1:
    print(a)
    exit(0)
b = s.find(':', a)
if b == -1:
    print(b)
    exit(0)

c = s.rfind(']', b)
if c == -1:
    print(c)
    exit(0)

d = s.rfind(':', b + 1, c)
if d == -1:
    print(d)
    exit(0)

cnt = 0
for i in range(b, c):
    cnt += (s[i] == '|')
print(cnt + 4)


s = input()
a = s.find('[')
if a == -1:
    print(a)
    exit(0)
b = s.find(':', a)
if b == -1:
    print(b)
    exit(0)

c = s.rfind(']', b)
if c == -1:
    print(c)
    exit(0)

d = s.rfind(':', b + 1, c)
if d == -1:
    print(d)
    exit(0)

cnt = 0
for i in range(b, c):
    cnt += (s[i] == '|')
print(cnt + 1)


n=list(input())
i=0
c=0
b1=0;b2=0
j=len(n)-1
while 1:
   if len(n)>=1 and n[0]!='[':
       del n[0]
   else:
        b1=1
   if len(n)>1 and n[len(n)-1]!=']':
       del n[len(n)-1]
   else:
       b2=1
   if b1==1 and b2==1:
       break
if len(n)>4:
    b1=0;b2=0
    i=1
    while 1:
       if len(n)>1 and n[1]!=':':
           del n[1]
       else:
            b1=1
       if len(n)>2 and n[len(n)-2]!=':':
           del n[len(n)-2]
       else:
           b2=1
       if b1==1 and b2==1:
           break
else:
    print(-1)
    c=1
if len(n)>4:
    b1=0;b2=0
    i=2
    while i<len(n)-2:
       if n[i]!='|':
           del n[i]
           i-=1
       i+=1
 #   print(n)
    print(len(n))
elif c==0:
    print(-1)


n=list(input())
i=0
c=0
b1=0;b2=0
j=len(n)-1
while 1:
   if n[i]!='[':
       del n[0]
   else:
        b1=1
   if n[len(n)-1]!=']':
       del n[len(n)-1]
   else:
       b2=1
   if b1==1 and b2==1:
       break
if len(n)>4:
    b1=0;b2=0
    i=1
    while 1:
       if len(n)>1 and n[1]!=':':
           del n[1]
       else:
            b1=1
       if n[len(n)-2]!=':':
           del n[len(n)-2]
       else:
           b2=1
       if b1==1 and b2==1:
           break
else:
    print(-1)
    c=1
if len(n)>4:
    b1=0;b2=0
    i=2
    while i<len(n)-2:
       if n[i]!='|':
           del n[i]
           i-=1
       i+=1
 #   print(n)
    print(len(n))
elif c:
    print(-1)


n=list(input())
i=0
c=0
b1=0;b2=0
j=len(n)-1
while i<j:
   if len(n)>=1 and n[i]=='[':
       b1=1
   else:
        i+=1
   if len(n)>1 and n[j]==']':
       b2=1
   else:
       j-=1
   if b1==1 and b2==1:
       break
if i<j and b1==1 and b2==1:
    b1=0;b2=0
    while i<j:
       if len(n)>1 and n[i]==':':
           b1=1
       else:
            i+=1
       if i<j and n[j]==':':
           b2=1
       else:
           j-=1
       if b1==1 and b2==1:
           break
else:
    print(-1)
    c=1
if c==0 and b1==1 and b2==1:
    b1=0;b2=0
    d=0
    while i<j:
       if n[i]=='|':
           d+=1
       i+=1
 #   print(n)
    print(d+4)
elif c==0:
    print(-1)


n=list(input())
i=0
c=0
b1=0;b2=0
j=len(n)-1
while i<j:
   if len(n)>=1 and n[i]=='[':
       b1=1
   else:
        i+=1
   if len(n)>1 and n[j]==']':
       b2=1
   else:
       j-=1
   if b1==1 and b2==1:
       break
if i<j:
    b1=0;b2=0
    while i<j:
       if len(n)>1 and n[i]==':':
           b1=1
       else:
            i+=1
       if i<j and n[j]==':':
           b2=1
       else:
           j-=1
       if b1==1 and b2==1:
           break
else:
    print(-1)
    c=1
if c==0:
    b1=0;b2=0
    d=0
    while i<j:
       if n[i]=='|':
           d+=1
       i+=1
 #   print(n)
    print(d+4)
elif c==0:
    print(-1)


#include <bits/stdc++.h>
#define vec(a) vector<a>
#define vecp(a,b) vector < pair< a, b > >
#define pb push_back
#define minpq priority_queue <long long int, vector<long long int>, greater<long long int> > pq;
#define f(i,a,b) for(long long int i=a;i<b;i++)
#define fr(i,a,b) for(long long int i=a;i>=b;i--)
#define tc long long int t; cin>>t; while(t--)
#define mp make_pair
#define mapp(a,b) map<a, b>
#define umapp(a,b) unordered_map<a ,b>
#define mem(d,val) memset(d,val,sizeof(d))
using namespace std;
#define mod 1000000007
typedef long long int ll;

int main(){
   ll n,d,e;
   cin>>n>>d>>e;
   set<ll> price;
   price.insert(5*e);
   price.insert(10*e);
   price.insert(20*e);
   price.insert(50*e);
   price.insert(100*e);
   price.insert(200*e);
   price.insert(1*d);
   price.insert(2*d);
   price.insert(5*d);
   price.insert(10*d);
   price.insert(20*d);
   price.insert(50*d);
   price.insert(100*d);
   bool mark[n+1]={false};
   int start = *price.begin();
   // cout<<start;
   mark[start]=true;
   ll ans=0;
   for(ll i = start ;i<=n;i++){
   	if(mark[i]){
   		ans = i;
   		for(auto it = price.begin();it!=price.end();it++){
   			if(i+*it <= n){
	   			mark[i+*it]=true;
	   		}
   		}
   	}
   }
   cout<<n-ans;

}


#include <bits/stdc++.h>
#define vec(a) vector<a>
#define vecp(a,b) vector < pair< a, b > >
#define pb push_back
#define minpq priority_queue <long long int, vector<long long int>, greater<long long int> > pq;
#define f(i,a,b) for(long long int i=a;i<b;i++)
#define fr(i,a,b) for(long long int i=a;i>=b;i--)
#define tc long long int t; cin>>t; while(t--)
#define mp make_pair
#define mapp(a,b) map<a, b>
#define umapp(a,b) unordered_map<a ,b>
#define mem(d,val) memset(d,val,sizeof(d))
using namespace std;
#define mod 1000000007
typedef long long int ll;

int main(){
   ll n,d,e;
   cin>>n>>d>>e;
   set<ll> price;
   price.insert(5*e);
   price.insert(10*e);
   price.insert(20*e);
   price.insert(50*e);
   price.insert(100*e);
   price.insert(200*e);
   price.insert(1*d);
   price.insert(2*d);
   price.insert(5*d);
   price.insert(10*d);
   price.insert(20*d);
   price.insert(50*d);
   price.insert(100*d);
   bool mark[n+1]={false};
   for(auto it = price.begin();it!=price.end();it++){
		if(*it <= n){
			mark[*it]=true;
		}
	}
	ll start = *price.begin();
	ll ans = 0;
   for(ll i = start ;i<=n;i++){
   	if(mark[i]){
   		ans = i;
   		for(auto it = price.begin();it!=price.end();it++){
   			if((n-i)%*it==0){
   				cout<<0;
   				return 0;
   			}
   			if(i+*it <= n){
	   			mark[i+*it]=true;
	   		}
   		}
   	}
   }
   cout<<n-ans;

}


#include <bits/stdc++.h>
#define vec(a) vector<a>
#define vecp(a,b) vector < pair< a, b > >
#define pb push_back
#define minpq priority_queue <long long int, vector<long long int>, greater<long long int> > pq;
#define f(i,a,b) for(long long int i=a;i<b;i++)
#define fr(i,a,b) for(long long int i=a;i>=b;i--)
#define tc long long int t; cin>>t; while(t--)
#define mp make_pair
#define mapp(a,b) map<a, b>
#define umapp(a,b) unordered_map<a ,b>
#define mem(d,val) memset(d,val,sizeof(d))
using namespace std;
#define mod 1000000007
typedef long long int ll;

int main(){
   ll n,d,e;
   cin>>n>>d>>e;
   set<ll> price;
   price.insert(5*e);
   price.insert(10*e);
   price.insert(20*e);
   price.insert(50*e);
   price.insert(100*e);
   price.insert(200*e);
   price.insert(1*d);
   price.insert(2*d);
   price.insert(5*d);
   price.insert(10*d);
   price.insert(20*d);
   price.insert(50*d);
   price.insert(100*d);
   for(auto it = price.rbegin(); it!=price.rend();it++){
   		int k = *it;
   		int p = n/k;
   		// cout<< k <<" "<<p<<"\n";
   		n -= p*k;
   }
   cout<<n;
}


#include <bits/stdc++.h>
#define vec(a) vector<a>
#define vecp(a,b) vector < pair< a, b > >
#define pb push_back
#define minpq priority_queue <long long int, vector<long long int>, greater<long long int> > pq;
#define f(i,a,b) for(long long int i=a;i<b;i++)
#define fr(i,a,b) for(long long int i=a;i>=b;i--)
#define tc long long int t; cin>>t; while(t--)
#define mp make_pair
#define mapp(a,b) map<a, b>
#define umapp(a,b) unordered_map<a ,b>
#define mem(d,val) memset(d,val,sizeof(d))
using namespace std;
#define mod 1000000007
typedef long long int ll;

int main(){
   ll n,d,e;
   cin>>n>>d>>e;
   set<ll> price;
   price.insert(5*e);
   price.insert(10*e);
   price.insert(20*e);
   price.insert(50*e);
   price.insert(100*e);
   price.insert(200*e);
   price.insert(1*d);
   price.insert(2*d);
   price.insert(5*d);
   price.insert(10*d);
   price.insert(20*d);
   price.insert(50*d);
   price.insert(100*d);
   bool mark[n+1]={false};
   for(auto it = price.begin();it!=price.end();it++){
		if(*it <= n){
			mark[*it]=true;
		}
	}
	ll start = *price.begin();
	ll ans = 0;
   for(ll i = start ;i<=n;i++){
   	if(mark[i]){
   		// cout<<i<<" ";
   		ans = i;
   		for(auto it = price.begin();it!=price.end();it++){
   			if(i+*it <= n){
	   			mark[i+*it]=true;
	   		}
   		}
   	}
   }
   cout<<n-ans;

}


#include <bits/stdc++.h>
#define vec(a) vector<a>
#define vecp(a,b) vector < pair< a, b > >
#define pb push_back
#define minpq priority_queue <long long int, vector<long long int>, greater<long long int> > pq;
#define f(i,a,b) for(long long int i=a;i<b;i++)
#define fr(i,a,b) for(long long int i=a;i>=b;i--)
#define tc long long int t; cin>>t; while(t--)
#define mp make_pair
#define mapp(a,b) map<a, b>
#define umapp(a,b) unordered_map<a ,b>
#define mem(d,val) memset(d,val,sizeof(d))
using namespace std;
#define mod 1000000007
typedef long long int ll;

int main(){
   ll n,d,e;
   cin>>n>>d>>e;
   set<ll> price;
   price.insert(5*e);
   price.insert(10*e);
   price.insert(20*e);
   price.insert(50*e);
   price.insert(100*e);
   price.insert(200*e);
   price.insert(1*d);
   price.insert(2*d);
   price.insert(5*d);
   price.insert(10*d);
   price.insert(20*d);
   price.insert(50*d);
   price.insert(100*d);

	for(auto it = price.begin();it!=price.end();it++){
		while(n>=*it){
			n-=*it;
		}
	}
   cout<<n;

}


#include <bits/stdc++.h>
#define vec(a) vector<a>
#define vecp(a,b) vector < pair< a, b > >
#define pb push_back
#define minpq priority_queue <long long int, vector<long long int>, greater<long long int> > pq;
#define f(i,a,b) for(long long int i=a;i<b;i++)
#define fr(i,a,b) for(long long int i=a;i>=b;i--)
#define tc long long int t; cin>>t; while(t--)
#define mp make_pair
#define mapp(a,b) map<a, b>
#define umapp(a,b) unordered_map<a ,b>
#define mem(d,val) memset(d,val,sizeof(d))
using namespace std;
#define mod 1000000007
typedef long long int ll;

int main(){
   ll n,d,e;
   cin>>n>>d>>e;
   set<ll> price;
   price.insert(5*e);
   price.insert(1*d);
   bool mark[n+1]={false};
   for(auto it = price.begin();it!=price.end();it++){
		if(*it <= n){
			mark[*it]=true;
		}
	}
	ll start = *price.begin();
	ll ans = 0;
   for(ll i = start ;i<=n;i++){
   	if(mark[i]){
   		ans = i;
   		for(auto it = price.begin();it!=price.end();it++){
   			if((n-i)%*it==0){
   				cout<<0;
   				return 0;
   			}
   			if(i+*it <= n){
	   			mark[i+*it]=true;
	   		}
   		}
   	}
   }
   cout<<n-ans;

}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

//-----------------------------------------------------------//

int main()
{
    fast;

    // int t;
    // cin>>t;

    // while(t--)
    // {

    // }

    // ll n;
    // cin>>n;

    // ll a[n];
    // for(int i=0;i<n;i++)
    // {
    // 	cin>>a[n];
    // }

    ll n;
    int e,d;

    cin>>n>>d>>e;

    int a[] = {1 , 2, 5, 10, 20, 50, 100};
    int b[] = {5, 10, 20, 50, 100, 200};

    ll res1=n,res2=n;

    for(int i=6;i>=0;i--)
    {
        if(a[i]*d <= n)
        {
            res1 = (n%(a[i]*d));
            break;
        }
    }
    for(int i=5;i>=0;i--)
    {
        if(b[i]*e <= res1)
        {
            res1 = (res1%(b[i]*e));
            break;
        }
    }

    for(int i=5;i>=0;i--)
    {
        if(b[i]*e <= n)
        {
            res2 = (n%(b[i]*e));
            break;
        }
    }
    cout<<res2<<endl;
    for(int i=6;i>=0;i--)
    {
        if(a[i]*d <= res2)
        {
            res2 = (res2%(a[i]*d));
            break;
        }
    }
    //cout<<res1<<" "<<res2<<endl;
    cout<<min(res1,res2)<<endl;
    return 0;
}

/*

test case

*/


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

//-----------------------------------------------------------//

int main()
{
    fast;
    int n,e,d;

    cin>>n>>d>>e;

    int a[] = {1, 2, 5, 10, 20, 50, 100};
    int b[] = {5, 10, 20, 50, 100, 200};

    int res1=n,res2=n;

    bool flag=1;
    while(flag)
    {
        flag=0;
        for(int i=6;i>=0;i--)
        {
            if(a[i]*d <= res1)
            {
                res1 = (res1%(a[i]*d));
                flag=1;
                break;
            }
        }
        for(int i=5;i>=0;i--)
        {
            if(b[i]*e <= res1)
            {
                res1 = (res1%(b[i]*e));
                flag=1;
                break;
            }
        }
        //cout<<res1<<endl;
    }
    flag=1;
    while(flag)
    {
        flag=0;
        for(int i=5;i>=0;i--)
        {
            if(b[i]*e <= res2)
            {
                res2 = (res2%(b[i]*e));
                flag=1;
                break;
            }
        }
        //cout<<res2<<endl;
        for(int i=6;i>=0;i--)
        {
            if(a[i]*d <= res2)
            {
                res2 = (res2%(a[i]*d));
                flag=1;
                break;
            }
        }
    }
    //cout<<res1<<" "<<res2<<endl;
    cout<<min(res1,res2)<<endl;
    return 0;
}

/*

test case

*/


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll power(ll a , ll b,ll modi)
{
    ll res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % modi ;
        }
        b/=2 ;
        a = (a*a) % modi ;
    }
    return res ;
}

//-----------------------------------------------------------//

int main()
{
    fast;

    int n,d,e;
    cin>>n>>d>>e;

    int res=0;
    int diff = n;

    for(int i=0;i<=(n/d);i++)
    {
        for(int j=0;j<=(n/(5*e));j++)
        {
            if(n - (i*d + j*(5*e)) >= 0 && n - (i*d + j*(5*e)) < diff)
                diff = n - (i*d + j*(5*e));
        }
    }
    cout<<diff<<endl;
    return 0;
}

/*

test case

*/


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll power(ll a , ll b,ll modi)
{
    ll res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % modi ;
        }
        b/=2 ;
        a = (a*a) % modi ;
    }
    return res ;
}

//-----------------------------------------------------------//

int main()
{
    fast;

    int n,d,e;
    cin>>n>>d>>e;

    int res=0;
    int diff = n;
    bool flag=1;

    for(int i=0;i<=(n/d);i++)
    {
        for(int j=0;j<=(n/(5*e));j++)
        {
            if(n - (i*d + j*(5*e)) < 0)
            {
                flag=0;
                break;
            }
            if(n - (i*d + j*(5*e)) < diff)
                diff = n - (i*d + j*(5*e));
        }
    }
    cout<<diff<<endl;
    return 0;
}

/*

test case

*/


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll power(ll a , ll b,ll modi)
{
    ll res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % modi ;
        }
        b/=2 ;
        a = (a*a) % modi ;
    }
    return res ;
}

//-----------------------------------------------------------//

int main()
{
    fast;

    int n,d,e;
    cin>>n>>d>>e;

    // int res=0;
    // int diff = n;

    // for(int i=0;i<=(n/d);i++)
    // {
    //     for(int j=0;j<=(n/(5*e));j++)
    //     {
    //         if(n - (i*d + j*(5*e)) < 0)
    //             break;
    //         if(n - (i*d + j*(5*e)) < diff)
    //             diff = n - (i*d + j*(5*e));
    //         if(diff == 0)
    //         {
    //             cout<<diff<<endl;
    //             return 0;
    //         }
    //     }
    // }
    // cout<<diff<<endl;
    // cout<<gcd(55,350)<<endl;

    vector <int> v(n+1,n);
    v[0]=0;
    for(int i=0;i<n+1;i++)
    {
        if(i-d >= 0 )
            v[i]=min(v[i],v[i-d]+1);
    }
    for(int i=0;i<n+1;i++)
    {
        if(i-5*e >= 0)
            v[i]=min(v[i],v[i-5*e]+1);
    }
    int ans=0;
    for(int i=n;i>=0;i--)
    {
        if(v[i] < n)
        {
            ans = i;
            break;
        }
    }
    cout<<(n-ans)<<endl;
    return 0;
}

/*

test case

*/


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

//-----------------------------------------------------------//

int main()
{
    fast;

    // int t;
    // cin>>t;

    // while(t--)
    // {

    // }

    // ll n;
    // cin>>n;

    // ll a[n];
    // for(int i=0;i<n;i++)
    // {
    // 	cin>>a[n];
    // }

    ll n;
    int e,d;

    cin>>n>>d>>e;

    int a[] = {1 , 2, 5, 10, 20, 50, 100};
    int b[] = {5, 10, 20, 50, 100, 200};

    ll res1=n,res2=n;

    for(int i=6;i>=0;i--)
    {
        if(a[i]*d <= n)
        {
            res1 = (n%(a[i]*d));
            break;
        }
    }
    for(int i=5;i>=0;i--)
    {
        if(b[i]*e <= res1)
        {
            res1 = (res1%(b[i]*e));
            break;
        }
    }

    for(int i=5;i>=0;i--)
    {
        if(b[i]*e <= n)
        {
            res2 = (n%(b[i]*e));
            break;
        }
    }
    //cout<<res2<<endl;
    for(int i=6;i>=0;i--)
    {
        if(a[i]*d <= res2)
        {
            res2 = (res2%(a[i]*d));
            break;
        }
    }
    //cout<<res1<<" "<<res2<<endl;
    cout<<min(res1,res2)<<endl;
    return 0;
}

/*

test case

*/


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll power(ll a , ll b,ll modi)
{
    ll res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % modi ;
        }
        b/=2 ;
        a = (a*a) % modi ;
    }
    return res ;
}

//-----------------------------------------------------------//

int main()
{
    fast;

    int n,d,e;
    cin>>n>>d>>e;

    int res=0;
    int diff = n;
    bool flag=1;

    for(int i=0;i<=(n/d);i++)
    {
        for(int j=0;j<=(n/(5*e));j++)
        {
            if(n - (i*d + j*(5*e)) < 0)
            {
                flag=0;
                break;
            }
            if(n - (i*d + j*(5*e)) < diff)
                diff = n - (i*d + j*(5*e));
        }
        if(flag == 0)
            break;
    }
    cout<<diff<<endl;
    return 0;
}

/*

test case

*/


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll power(ll a , ll b,ll modi)
{
    ll res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % modi ;
        }
        b/=2 ;
        a = (a*a) % modi ;
    }
    return res ;
}

//-----------------------------------------------------------//

int main()
{
    fast;

    int n,d,e;
    cin>>n>>d>>e;

    // int res=0;
    // int diff = n;

    // for(int i=0;i<=(n/d);i++)
    // {
    //     for(int j=0;j<=(n/(5*e));j++)
    //     {
    //         if(n - (i*d + j*(5*e)) < 0)
    //             break;
    //         if(n - (i*d + j*(5*e)) >= 0 && n - (i*d + j*(5*e)) < diff)
    //             diff = n - (i*d + j*(5*e));
    //     }
    // }
    // cout<<diff<<endl;
    // cout<<gcd(55,350)<<endl;

    vector <ll> v(n+1,INT_MAX);
    v[0]=0;
    for(int i=0;i<n+1;i++)
    {
        if(i-d >= 0)
            v[i]=min(v[i],v[i-d]+1);
    }
    for(int i=0;i<n+1;i++)
    {
        if(i-5*e >= 0)
            v[i]=min(v[i],v[i-5*e]+1);
    }
    int ans=0;
    for(int i=n;i>=0;i--)
    {
        if(v[i] < INT_MAX)
        {
            ans = i;
            break;
        }
    }
    cout<<(n-ans)<<endl;
    return 0;
}

/*

test case

*/


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll power(ll a , ll b,ll modi)
{
    ll res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % modi ;
        }
        b/=2 ;
        a = (a*a) % modi ;
    }
    return res ;
}

//-----------------------------------------------------------//

int main()
{
    fast;

    int n,d,e;
    cin>>n>>d>>e;

    int res=0;
    int diff = n;
    bool flag=1;

    for(int i=0;i<=(n/d);i+=d)
    {
        for(int j=0;j<=(n/(5*e));j+=(5*e))
        {
            if(n - (i*d + j*(5*e)) < 0)
            {
                flag=0;
                break;
            }
            if(n - (i*d + j*(5*e)) < diff)
                diff = n - (i*d + j*(5*e));
        }
    }
    cout<<diff<<endl;
    return 0;
}

/*

test case

*/


#include<bits/stdc++.h>
using namespace std;
long long int m=100000000;
int main()
{
   long long int n,d,e;
    cin>>n>>d>>e;
   long long int c=n/d;
   long long int f=n/e;
   long long int g=n%d;
   long long int h=n%e;
    for(int i=0;i<=c;i++)
    {
        m=min((n-i*d)%e,m);
    }
    cout<<m;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long int m=100000000;
int main()
{
   long long int n,d,e;
    cin>>n>>d>>e;
   long long int c=n/d;
   long long int f=n/e;
   e=5*e;
    for(int i=0;i<=f;i++)
    {
        m=min((n-i*d)%e,m);
    }
    cout<<m;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
set<int>s;
int main()
{
   long long int n,d,e;
    cin>>n>>d>>e;
   long long int c=n/d;
   long long int f=n/e;
   long long int g=n%d;
   long long int h=n%e;
    if(g<e&&h<d&&g!=0&&h!=0)
    {
        cout<<max(g,h);
        return 0;
    }
     if(g==e||h==d)
    {
        cout<<0;
        return 0;
    }
     if(g>e||h>d)
    {
       long long int m=g%e;
       long long int n=h%d;
        cout<<min(m,n);
        return 0;
    }
    if(g==0||h==0)
    {
        cout<<0;
        return 0;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long int m=100000000;
int main()
{
   long long int n,d,e;
    cin>>n>>d>>e;
   long long int c=n/d;
   long long int f=n/e;
   e=5*e;
    for(int i=0;i<=c;i++)
    {
        m=min((n-i*d)%e,m);
    }
    cout<<m;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
set<int>s;
int main()
{
   int n,d,e;
    cin>>n>>d>>e;
    int c=n/d;
    int f=n/e;
    int g=n%d;
    int h=n%e;
    if(c==f&&g<e&&h<d)
    {
        cout<<max(g,h);
    }
    else if(g==e||h==d)
    {
        cout<<0;
    }
    else if(g>e||h>d)
    {
        int m=g%e;
        int n=h%d;
        cout<<min(m,n);
    }
    else if(g==0||h==0)
    {
        cout<<0;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
set<int>s;
int main()
{
   int n,d,e;
    cin>>n>>d>>e;
    int c=n/d;
    int f=n/e;
    int g=n%d;
    int h=n%e;
    if(c==f&&g<e&&h<d&&g!=0&&h!=0)
    {
        cout<<max(g,h);
        return 0;
    }
     if(g==e||h==d)
    {
        cout<<0;
        return 0;
    }
     if(g>e||h>d)
    {
        int m=g%e;
        int n=h%d;
        cout<<min(m,n);
        return 0;
    }
    if(g==0||h==0)
    {
        cout<<0;
        return 0;
    }

    return 0;
}


#include"bits/stdc++.h"
#define mod1 998244353
#define mod 1000000007
#define LL long long
#define int long long
#define INF 1e17
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define vi vector<int>
#define fast ios_base::sync_with_stdio(false)
#define all(a) (a).begin(),(a).end()
#define mp make_pair
using namespace std;
int add(int a,int b){return (a%mod1+b%mod1)%mod1;}
int mul(int a,int b){return ((a%mod1)*(b%mod1))%mod1;}
int binary_expo(int base,int expo){
    int res = 1;
    while(expo){
        if(expo%2){
            res = mul(res,base);
        }
        expo /= 2;
        base = mul(base,base);
    }
    return res;
}
map <int,int> dp;
vi v;
int fnc(int n){
    if(dp.find(n) != dp.end()){
        return dp[n];
    }
    int maxx = 0;
    for(int i=0;i<v.size();i++){
        if(n >= v[i]){
            maxx = max(maxx,v[i] + fnc(n - v[i]));
        }
    }
    return dp[n] = maxx;
}
void solve(int tc){
    int A[] = {1,2,5,10,20,50,100};
    int B[] = {5, 10, 20, 50, 100, 200};
    int n,d,e;
    cin >> n >> d >> e;
    //vi v;
    for(int i=0;i<7;i++){
        A[i] = A[i] * d;
        v.pb(A[i]);
    }
    for(int i=0;i<6;i++){
        B[i] = B[i] * e;
        v.pb(B[i]);
    }
    cout << n - fnc(n) << endl;
}
signed main(){
    int t,k;
    fast;
    t = 1;
    //cin >> t;
    int tc = 1;
    while(t--){
        solve(tc++);
    }
    return 0;
}


#include"bits/stdc++.h"
#define mod1 998244353
#define mod 1000000007
#define LL long long
#define int long long
#define INF 1e17
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define vi vector<int>
#define fast ios_base::sync_with_stdio(false)
#define all(a) (a).begin(),(a).end()
#define mp make_pair
using namespace std;
int add(int a,int b){return (a%mod1+b%mod1)%mod1;}
int mul(int a,int b){return ((a%mod1)*(b%mod1))%mod1;}
int binary_expo(int base,int expo){
    int res = 1;
    while(expo){
        if(expo%2){
            res = mul(res,base);
        }
        expo /= 2;
        base = mul(base,base);
    }
    return res;
}
void solve(int tc){
    int A[] = {1,2,5,10,20,50,100};
    int B[] = {5, 10, 20, 50, 100, 200};
    int n,d,e;
    cin >> n >> d >> e;
    vi v;
    for(int i=0;i<7;i++){
        A[i] = A[i] * d;
        v.pb(A[i]);
    }
    for(int i=0;i<6;i++){
        B[i] = B[i] * e;
        v.pb(B[i]);
    }
    sort(all(v));
    reverse(all(v));
    while(1){
        int f = 0;
        for(int i=0;i<v.size();i++){
            if(n >= v[i]){
                f = 1;
                n -= v[i];
                break;
            }
        }
        if(!f){
            break;
        }
    }
    cout << n << endl;
}
signed main(){
    int t,k;
    fast;
    t = 1;
    //cin >> t;
    int tc = 1;
    while(t--){
        solve(tc++);
    }
    return 0;
}


#include"bits/stdc++.h"
#define mod1 998244353
#define mod 1000000007
#define LL long long
#define int long long
#define INF 1e17
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define vi vector<int>
#define fast ios_base::sync_with_stdio(false)
#define all(a) (a).begin(),(a).end()
#define mp make_pair
using namespace std;
int add(int a,int b){return (a%mod1+b%mod1)%mod1;}
int mul(int a,int b){return ((a%mod1)*(b%mod1))%mod1;}
int binary_expo(int base,int expo){
    int res = 1;
    while(expo){
        if(expo%2){
            res = mul(res,base);
        }
        expo /= 2;
        base = mul(base,base);
    }
    return res;
}
unordered_map <int,int> dp;
vi v;
int fnc(int n){
     cout << n << endl;
    if(dp.find(n)!=dp.end()){
        return dp[n];
    }
    int maxx = 0;
    for(int i=0;i<v.size();i++){
        if(n >= v[i]){
            maxx = max(maxx,v[i] + fnc(n - v[i]));
        }
    }
    return dp[n] = maxx;
}
void solve(int tc){
    int A[] = {1,2,5,10,20,50,100};
    int B[] = {5, 10, 20, 50, 100, 200};
    int n,d,e;
    cin >> n >> d >> e;
    //vi v;
    for(int i=0;i<7;i++){
        A[i] = A[i] * d;
        v.pb(A[i]);
    }
    for(int i=0;i<6;i++){
        B[i] = B[i] * e;
        v.pb(B[i]);
    }
    cout << n - fnc(n) << endl;
}
signed main(){
    int t,k;
    fast;
    t = 1;
    //cin >> t;
    int tc = 1;
    while(t--){
        solve(tc++);
    }
    return 0;
}


#include"bits/stdc++.h"
#define mod1 998244353
#define mod 1000000007
#define LL long long
#define int long long
#define INF 1e17
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define vi vector<int>
#define fast ios_base::sync_with_stdio(false)
#define all(a) (a).begin(),(a).end()
#define mp make_pair
using namespace std;
int add(int a,int b){return (a%mod1+b%mod1)%mod1;}
int mul(int a,int b){return ((a%mod1)*(b%mod1))%mod1;}
int binary_expo(int base,int expo){
    int res = 1;
    while(expo){
        if(expo%2){
            res = mul(res,base);
        }
        expo /= 2;
        base = mul(base,base);
    }
    return res;
}
map <int,int> dp;
vi v;
int fnc(int n){
    int maxx = 0;
    for(int i=0;i<v.size();i++){
        if(n >= v[i]){
            maxx = max(maxx,v[i] + fnc(n - v[i]));
        }
    }
    return maxx;
}
void solve(int tc){
    int A[] = {1,2,5,10,20,50,100};
    int B[] = {5, 10, 20, 50, 100, 200};
    int n,d,e;
    cin >> n >> d >> e;
    //vi v;
    for(int i=0;i<7;i++){
        A[i] = A[i] * d;
        v.pb(A[i]);
    }
    for(int i=0;i<6;i++){
        B[i] = B[i] * e;
        v.pb(B[i]);
    }
    cout << n - fnc(n) << endl;
}
signed main(){
    int t,k;
    fast;
    t = 1;
    //cin >> t;
    int tc = 1;
    while(t--){
        solve(tc++);
    }
    return 0;
}


#include"bits/stdc++.h"
#define mod1 998244353
#define mod 1000000007
#define LL long long
#define int long long
#define INF 1e17
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define vi vector<int>
#define fast ios_base::sync_with_stdio(false)
#define all(a) (a).begin(),(a).end()
#define mp make_pair
using namespace std;
int add(int a,int b){return (a%mod1+b%mod1)%mod1;}
int mul(int a,int b){return ((a%mod1)*(b%mod1))%mod1;}
int binary_expo(int base,int expo){
    int res = 1;
    while(expo){
        if(expo%2){
            res = mul(res,base);
        }
        expo /= 2;
        base = mul(base,base);
    }
    return res;
}
unordered_map <int,int> dp;
vi v;
int fnc(int n){
     //cout << n << endl;
    if(dp.find(n)!=dp.end()){
        return dp[n];
    }
    int maxx = 0;
    for(int i=0;i<v.size();i++){
        if(n >= v[i]){
            maxx = max(maxx,v[i] + fnc(n - v[i]));
        }
    }
    return dp[n] = maxx;
}
void solve(int tc){
    int n,d,e;
    cin >> n >> d >> e;
    int minn = n;
    e = e * 5;
    for(int i=0;i*e <= n;i++){
        minn = min(minn,(n-i*e)%d);
    }
    cout << minn << endl;
}
signed main(){
    int t,k;
    fast;
    t = 1;
    //cin >> t;
    int tc = 1;
    while(t--){
        solve(tc++);
    }
    return 0;
}


#include"bits/stdc++.h"
#define mod1 998244353
#define mod 1000000007
#define LL long long
#define int long long
#define INF 1e17
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define vi vector<int>
#define fast ios_base::sync_with_stdio(false)
#define all(a) (a).begin(),(a).end()
#define mp make_pair
using namespace std;
int add(int a,int b){return (a%mod1+b%mod1)%mod1;}
int mul(int a,int b){return ((a%mod1)*(b%mod1))%mod1;}
int binary_expo(int base,int expo){
    int res = 1;
    while(expo){
        if(expo%2){
            res = mul(res,base);
        }
        expo /= 2;
        base = mul(base,base);
    }
    return res;
}
map <int,int> dp;
vi v;
int fnc(int n){
    int maxx = 0;
    for(int i=0;i<v.size();i++){
        if(n >= v[i]){
            maxx = max(maxx,v[i] + fnc(n - v[i]));
        }
    }
}
void solve(int tc){
    int A[] = {1,2,5,10,20,50,100};
    int B[] = {5, 10, 20, 50, 100, 200};
    int n,d,e;
    cin >> n >> d >> e;
    //vi v;
    for(int i=0;i<7;i++){
        A[i] = A[i] * d;
        v.pb(A[i]);
    }
    for(int i=0;i<6;i++){
        B[i] = B[i] * e;
        v.pb(B[i]);
    }
    cout << n - fnc(n) << endl;
}
signed main(){
    int t,k;
    fast;
    t = 1;
    //cin >> t;
    int tc = 1;
    while(t--){
        solve(tc++);
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
main()
{
  ll n,d,e;
  cin>>n>>d>>e;
  if(n%d==0 || n%e==0)
  cout<<"0"<<"\n";
  else{
  ll ans=n;
  ll x= n/(5*e);
  if(x>0)
  x=n-x*e*5;
  else
  x=n;
  ans=min(ans,x);
  if(x>d)
  {
    ll z=x/d;
    x=x-z*d;
    ans=min(ans,x);
  }
  cout<<ans<<"\n";
  }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
main()
{
  ll n,d,e;
  cin>>n>>d>>e;
  ll x= n/d;
  x= n-x*d;
  ll ans=0;
  ll y= n/(e*5);
  if(y>0)
  {
    ll x2;
    y=n-y*(e*5);
    if(y>d)
    {
      x2=y/d;
      x2=y-x2*d;
    }
    ans= min(x2,x);
  }
  else
  ans=x;
  cout<<ans<<"\n";
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
main()
{
  ll n,d,e;
  cin>>n>>d>>e;
  ll ans= n;
  ll x= n/d;
  if(x>0){
  x=n-x*d;
  ans=x;
  if(x>=e*5)
  {
    ll z=x/(e*5);
    z=x-e*5*z;
    ans=min(x,ans);
  }}
  ll y = n/(e*5);
  if(y>0){
  y=n-y*e*5;
  ans=min(ans,y);
  if(y>=d)
  {
    ll z= y/d;
    z=y-z*d;
    ans=min(ans,z);

  }}
  cout<<ans<<"\n";
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
main()
{
  ll n,d,e;
  cin>>n>>d>>e;
  ll ans=0;
  ll x= n/d;
  x= n-x*d;
  ans=x;
  if(x>=e)
  {
    ll x3= x/(5*e);
    x3=x-x3*5*e;
    ans=min(x3,ans);
  }
  ll y= n/(e*5);
  if(y>0)
  {
    ll x2;
    y=n-y*(e*5);
    if(y>=d)
    {
      x2=y/d;
      x2=y-x2*d;
    }
    ans= min(x2,ans);
    ans=min(ans,y);
  }
  cout<<ans<<"\n";
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
main()
{
  ll n,d,e;
  cin>>n>>d>>e;
  ll a[]={1 , 2, 5, 10, 20, 50, 100};
  ll b[]={5 , 10, 20, 50, 100, 200};
  ll ans=n;
  for(ll i=0;i<7;i++)
  {
    for(ll j=0;j<6;j++)
    {
      ll x= a[i]*d;
      ll y= b[j]*e;
      ll xx= max(x,y);
      ll yy= min(x,y);
      ll z= n/xx;
      if(z>0)
      z=n-z*xx;
      else
      z=n;
      if(z>yy)
      {
        ll z2=z/yy;
        z2=z-z2*yy;
        z=z2;
      }
      ans=min(ans,z);
    }
  }
  cout<<ans<<"\n";
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
main()
{
  ll n,d,e;
  cin>>n>>d>>e;
  ll ans= n;
  ll x= n/d;
  if(x>0){
  x=n-x*d;
  ans=x;
  if(x>=e*5)
  {
    ll z=x/(e*5);
    z=x-e*5*z;
    ans=min(z,ans);
  }}
  ll y = n/(e*5);
  if(y>0){
  y=n-y*e*5;
  ans=min(ans,y);
  if(y>=d)
  {
    ll z= y/d;
    z=y-z*d;
    ans=min(ans,z);

  }}
  cout<<ans<<"\n";
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
main()
{
  ll n,d,e;
  cin>>n>>d>>e;
  ll ans=n;
  for(ll i=0;i*e*5<=n;i++)
  {
    ans=min(ans,(n-i*e*5)%d);
  }
  cout<<ans<<"\n";
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
main()
{
  ll n,d,e;
  cin>>n>>d>>e;
  ll a[]={1 , 2, 5, 10, 20, 50, 100};
  ll b[]={5 , 10, 20, 50, 100, 200};
  ll ans=n;
  for(ll i=0;i<7;i++)
  {
    for(ll j=0;j<6;j++)
    {
      if(d*a[i]>n && e*b[j]>n)
      continue;
      ll x= a[i]*d;
      ll y= b[j]*e;
      ll xx= max(x,y);
      ll yy= min(x,y);
      ll z= n/xx;
      if(z>0)
      z=n-z*xx;
      else
      z=n;
      if(z>yy)
      {
        ll z2=z/yy;
        z2=z-z2*yy;
        z=z2;
      }
      ans=min(ans,z);
    }
  }
  cout<<ans<<"\n";
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
main()
{
  ll n,d,e;
  cin>>n>>d>>e;
  ll a[]={1 , 2, 5, 10, 20, 50, 100};
  ll b[]={5 , 10, 20, 50, 100, 200};
  ll ans=n;
  for(ll i=0;i<7;i++)
  {
    for(ll j=0;j<6;j++)
    {
      if(d*a[i]>n && e*b[j]>n)
      continue;
      ll x= a[i]*d;
      ll y= b[j]*e;
      ll xx= max(x,y);
      ll yy= min(x,y);
      ll z= n/xx;
      if(z>0)
      z=n-z*xx;
      else
      z=n;
      if(z>=yy)
      {
        ll z2=z/yy;
        z2=z-z2*yy;
        z=z2;
      }
      ans=min(ans,z);
    }
  }
  cout<<ans<<"\n";
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
main()
{
  ll n,d,e;
  cin>>n>>d>>e;
  ll ans=n;
  ll x= max(d,5*e);
  ll y= min(d,5*e);
  ll z= n/x;
  if(z>0)
  {
    z=n-z*x;
  }
  else
  z=n;
  //cout<<z<<'\n';
  if(z>=y)
  {
    ll z2= z/y;
    z2=z-z2*y;
    z=z2;
  }
  ans=min(ans,z);
 // cout<<ans<<"\n";

 ll ans2=n;
   y= max(d,5*e);
   x= min(d,5*e);
   z= n/x;
  if(z>0)
  {
    z=n-z*x;
  }
  else
  z=n;
  //cout<<z<<'\n';
  if(z>=y)
  {
    ll z2= z/y;
    z2=z-z2*y;
    z=z2;
  }
ans2=min(ans2,z);
ans=min(ans,ans2);
cout<<ans<<"\n";
}


    #include<bits/stdc++.h>
    using namespace std ;
    #define endl '\n'
    #define lld long long int
    #define ull unsigned long long int
    ull power(ull x, ull y){ull temp;if( y == 0)return 1;temp = power(x, y/2); if (y%2 == 0) return temp*temp;else return x*temp*temp; }
    ull gcdFactor(ull n){ ull tmp=n,res=0;for(ull i=1 ; i*i <=tmp ; i++){if(tmp%i==0){res++;if(tmp/i!=i)res++;}}return res;}
    #define ullmax ULLONG_MAX
    void Solution(void);
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        Solution();
        return 0;
    }

    // The difference between the novice and the master is that the master has failed more than the novice has tried
    // It is not over when you lose it is over when you quit
    // If you have time to think for a beautiful end, then live beautifully until the end

   void Solution(){
        int maxSum =0 , tmpSum =0 ;
        int n,d,e;
        cin>>n>>d>>e;
        e *= 5;
        int tmp1=n,tmp2=n;
        int i=n/e;
        if(i==100)
            i--;
        while(i--){
            if(tmp1>=e){
                tmp1 -= e;
            }else{
                break;
            }
        }
        tmp1 %= d;
        tmp2 = n%d;
        i=n/e;
        if(i==100)
            i--;
        while(i--){
            if(tmp2>=e){
                tmp2 -= e;
            }else{
                break;
            }
        }
        if(tmp1<tmp2){
            cout<<tmp1<<endl;
        }else{
            cout<<tmp2<<endl;
        }
	}


        #include<bits/stdc++.h>
        using namespace std ;
        #define endl '\n'
        #define lld long long int
        #define ull unsigned long long int
        ull power(ull x, ull y){ull temp;if( y == 0)return 1;temp = power(x, y/2); if (y%2 == 0) return temp*temp;else return x*temp*temp; }
        ull gcdFactor(ull n){ ull tmp=n,res=0;for(ull i=1 ; i*i <=tmp ; i++){if(tmp%i==0){res++;if(tmp/i!=i)res++;}}return res;}
        #define ullmax ULLONG_MAX
        void Solution(void);
        int main()
        {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            Solution();
            return 0;
        }

        // The difference between the novice and the master is that the master has failed more than the novice has tried
        // It is not over when you lose it is over when you quit
        // If you have time to think for a beautiful end, then live beautifully until the end

       void Solution(){
            int maxSum =0 , tmpSum =0 ;
            int n,d,e;
            cin>>n>>d>>e;
            e *= 5;
            int tmp1=n,tmp2=n;
            int i=n;
            while(i--){
                if(tmp1%d==0){
                    tmp1 = tmp1%d;
                }
                else
                    tmp1 -= e;
            }
            tmp1 %= d;
            i = n;
            while(i--){
                if(tmp2%e==0){
                    tmp2 = tmp2%e;
                }
                else
                    tmp2 -= d;
            }
            tmp2 %= e;
            if(tmp1<tmp2){
                cout<<tmp1<<endl;
            }else{
                cout<<tmp2<<endl;
            }
    	}


        #include<bits/stdc++.h>
        using namespace std ;
        #define endl '\n'
        #define lld long long int
        #define ull unsigned long long int
        ull power(ull x, ull y){ull temp;if( y == 0)return 1;temp = power(x, y/2); if (y%2 == 0) return temp*temp;else return x*temp*temp; }
        ull gcdFactor(ull n){ ull tmp=n,res=0;for(ull i=1 ; i*i <=tmp ; i++){if(tmp%i==0){res++;if(tmp/i!=i)res++;}}return res;}
        #define ullmax ULLONG_MAX
        void Solution(void);
        int main()
        {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            Solution();
            return 0;
        }

        // The difference between the novice and the master is that the master has failed more than the novice has tried
        // It is not over when you lose it is over when you quit
        // If you have time to think for a beautiful end, then live beautifully until the end

       void Solution(){
            int maxSum =0 , tmpSum =0 ,mntmp1 =INT_MAX,k1;
            int n,d,e;
            cin>>n>>d>>e;
            e *= 5;
            int tmp1=n,tmp2=n;
            int i=n/e;
            while(i--){
                    tmp1 -= e;
                    k1 = tmp1%d;
                    if(k1<mntmp1)
                        mntmp1 = k1;
            }
            mntmp1 = min(mntmp1,(tmp1%d));
            cout<<mntmp1;
    	}


    #include<bits/stdc++.h>
    using namespace std ;
    #define endl '\n'
    #define lld long long int
    #define ull unsigned long long int
    ull power(ull x, ull y){ull temp;if( y == 0)return 1;temp = power(x, y/2); if (y%2 == 0) return temp*temp;else return x*temp*temp; }
    ull gcdFactor(ull n){ ull tmp=n,res=0;for(ull i=1 ; i*i <=tmp ; i++){if(tmp%i==0){res++;if(tmp/i!=i)res++;}}return res;}
    #define ullmax ULLONG_MAX
    void Solution(void);
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        Solution();
        return 0;
    }

    // The difference between the novice and the master is that the master has failed more than the novice has tried
    // It is not over when you lose it is over when you quit
    // If you have time to think for a beautiful end, then live beautifully until the end

   void Solution(){
        int maxSum =0 , tmpSum =0 ;
        int n,d,e;
        cin>>n>>d>>e;
        e *= 5;
        int tmp1=n,tmp2=n;
        int i=n/e;
        while(i--){
            if(tmp1%d==0){
                tmp1 = tmp1%d;
            }
            else
                tmp1 -= e;
        }
        i = n/d;
        while(i--){
            if(tmp2%e==0){
                tmp2 = tmp2%e;
            }
            else
                tmp2 -= d;
        }
        if(tmp1<tmp2){
            cout<<tmp1<<endl;
        }else{
            cout<<tmp2<<endl;
        }
	}


    #include<bits/stdc++.h>
    using namespace std ;
    #define endl '\n'
    #define lld long long int
    #define ull unsigned long long int
    ull power(ull x, ull y){ull temp;if( y == 0)return 1;temp = power(x, y/2); if (y%2 == 0) return temp*temp;else return x*temp*temp; }
    ull gcdFactor(ull n){ ull tmp=n,res=0;for(ull i=1 ; i*i <=tmp ; i++){if(tmp%i==0){res++;if(tmp/i!=i)res++;}}return res;}
    #define ullmax ULLONG_MAX
    void Solution(void);
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        Solution();
        return 0;
    }

    // The difference between the novice and the master is that the master has failed more than the novice has tried
    // It is not over when you lose it is over when you quit
    // If you have time to think for a beautiful end, then live beautifully until the end

   void Solution(){
        int maxSum =0 , tmpSum =0 ;
        int n,d,e;
        cin>>n>>d>>e;
        e *= 5;
        int tmp1=n,tmp2=n;
        int i=n/e;
        while(i--){
            if(tmp1%d==0){
                tmp1 = tmp1%d;
            }
            else
                tmp1 -= e;
        }
        tmp1 %= d;
        i = n/d;
        while(i--){
            if(tmp2%e==0){
                tmp2 = tmp2%e;
            }
            else
                tmp2 -= d;
        }
        tmp2 %= e;
        if(tmp1<tmp2){
            cout<<tmp1<<endl;
        }else{
            cout<<tmp2<<endl;
        }
	}


    #include<bits/stdc++.h>
    using namespace std ;
    #define endl '\n'
    #define lld long long int
    #define ull unsigned long long int
    ull power(ull x, ull y){ull temp;if( y == 0)return 1;temp = power(x, y/2); if (y%2 == 0) return temp*temp;else return x*temp*temp; }
    ull gcdFactor(ull n){ ull tmp=n,res=0;for(ull i=1 ; i*i <=tmp ; i++){if(tmp%i==0){res++;if(tmp/i!=i)res++;}}return res;}
    #define ullmax ULLONG_MAX
    void Solution(void);
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        Solution();
        return 0;
    }

    // The difference between the novice and the master is that the master has failed more than the novice has tried
    // It is not over when you lose it is over when you quit
    // If you have time to think for a beautiful end, then live beautifully until the end

   void Solution(){
        int maxSum =0 , tmpSum =0 ;
        int n,d,e;
        cin>>n>>d>>e;
        e *= 5;
        int tmp1,tmp2;
        if(d<e){
            if(n%e<e){
                if(n>(e*100)){
                    e *= 99;
                }
                tmp1 = n%e;
                tmp1 = tmp1%d;
                tmp2 = n%d;
                tmp2 = tmp2%e;
            }else{
                tmp1 = n%d;
            }
        }else{
            if(n%d<d){
                tmp1 = n%d;
                if(tmp1>(e*100)){
                    e *= 99;
                }
                tmp1 = tmp1%e;
                if(n>(e*100)){
                    e *= 99;
                }
                tmp2 = n%e;
                tmp2 = tmp2%d;
            }else{
                if(n>(e*100)){
                    e *= 99;
                }
                tmp1 = n%e;
            }
        }
        if(tmp1<tmp2){
            cout<<tmp1<<endl;
        }else{
            cout<<tmp2<<endl;
        }
	}


    #include<bits/stdc++.h>
    using namespace std ;
    #define endl '\n'
    #define lld long long int
    #define ull unsigned long long int
    ull power(ull x, ull y){ull temp;if( y == 0)return 1;temp = power(x, y/2); if (y%2 == 0) return temp*temp;else return x*temp*temp; }
    ull gcdFactor(ull n){ ull tmp=n,res=0;for(ull i=1 ; i*i <=tmp ; i++){if(tmp%i==0){res++;if(tmp/i!=i)res++;}}return res;}
    #define ullmax ULLONG_MAX
    void Solution(void);
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        Solution();
        return 0;
    }

    // The difference between the novice and the master is that the master has failed more than the novice has tried
    // It is not over when you lose it is over when you quit
    // If you have time to think for a beautiful end, then live beautifully until the end

   void Solution(){
        int maxSum =0 , tmpSum =0 ;
        int n,d,e;
        cin>>n>>d>>e;
        e *= 5;
        int tmp1=n,tmp2=n;
        int i=99;
        while(i--){
            if(tmp1>=e){
                tmp1 -= e;
            }else{
                break;
            }
        }
        tmp1 %= d;
        tmp2 = n%d;
        i=99;
        while(i--){
            if(tmp2>=e){
                tmp2 -= e;
            }else{
                break;
            }
        }
        if(tmp1<tmp2){
            cout<<tmp1<<endl;
        }else{
            cout<<tmp2<<endl;
        }
	}


    #include<bits/stdc++.h>
    using namespace std ;
    #define endl '\n'
    #define lld long long int
    #define ull unsigned long long int
    ull power(ull x, ull y){ull temp;if( y == 0)return 1;temp = power(x, y/2); if (y%2 == 0) return temp*temp;else return x*temp*temp; }
    ull gcdFactor(ull n){ ull tmp=n,res=0;for(ull i=1 ; i*i <=tmp ; i++){if(tmp%i==0){res++;if(tmp/i!=i)res++;}}return res;}
    #define ullmax ULLONG_MAX
    void Solution(void);
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        Solution();
        return 0;
    }

    // The difference between the novice and the master is that the master has failed more than the novice has tried
    // It is not over when you lose it is over when you quit
    // If you have time to think for a beautiful end, then live beautifully until the end

   void Solution(){
        int maxSum =0 , tmpSum =0 ;
        int n,d,e;
        cin>>n>>d>>e;
        e *= 5;
        int tmp1,tmp2;
        if(d<e){
            if(n%e<e){
                tmp1 = n%e;
                tmp1 = tmp1%d;
                tmp2 = n%d;
                tmp2 = tmp2%e;
            }else{
                tmp1 = n%d;
            }
        }else{
            if(n%d<d){
                tmp1 = n%d;
                tmp1 = tmp1%e;
                tmp2 = n%e;
                tmp2 = tmp2%d;
            }else{
                tmp1 = n%e;
            }
        }
        if(tmp1<tmp2){
            cout<<tmp1<<endl;
        }else{
            cout<<tmp2<<endl;
        }
	}


        #include<bits/stdc++.h>
        using namespace std ;
        #define endl '\n'
        #define lld long long int
        #define ull unsigned long long int
        ull power(ull x, ull y){ull temp;if( y == 0)return 1;temp = power(x, y/2); if (y%2 == 0) return temp*temp;else return x*temp*temp; }
        ull gcdFactor(ull n){ ull tmp=n,res=0;for(ull i=1 ; i*i <=tmp ; i++){if(tmp%i==0){res++;if(tmp/i!=i)res++;}}return res;}
        #define ullmax ULLONG_MAX
        void Solution(void);
        int main()
        {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            Solution();
            return 0;
        }

        // The difference between the novice and the master is that the master has failed more than the novice has tried
        // It is not over when you lose it is over when you quit
        // If you have time to think for a beautiful end, then live beautifully until the end

       void Solution(){
            int maxSum =0 , tmpSum =0 ;
            int n,d,e;
            cin>>n>>d>>e;
            e *= 5;
            int tmp1=n,tmp2=n;
            int i=n/e;
            while(i--){
                if(tmp1%d==0){
                    tmp1 = tmp1%d;
                }
                else
                    tmp1 -= e;
            }
            tmp1 %= d;
            i = n/d;
            while(i--){
                if(tmp2%e==0){
                    tmp2 = tmp2%e;
                }
                else
                    tmp2 -= d;
            }
            tmp2 %= e;
            if(tmp1<tmp2){
                cout<<tmp1<<endl;
            }else{
                cout<<tmp2<<endl;
            }
    	}


        #include<bits/stdc++.h>
        using namespace std ;
        #define endl '\n'
        #define lld long long int
        #define ull unsigned long long int
        ull power(ull x, ull y){ull temp;if( y == 0)return 1;temp = power(x, y/2); if (y%2 == 0) return temp*temp;else return x*temp*temp; }
        ull gcdFactor(ull n){ ull tmp=n,res=0;for(ull i=1 ; i*i <=tmp ; i++){if(tmp%i==0){res++;if(tmp/i!=i)res++;}}return res;}
        #define ullmax ULLONG_MAX
        void Solution(void);
        int main()
        {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            Solution();
            return 0;
        }

        // The difference between the novice and the master is that the master has failed more than the novice has tried
        // It is not over when you lose it is over when you quit
        // If you have time to think for a beautiful end, then live beautifully until the end

       void Solution(){
            int maxSum =0 , tmpSum =0 ,mntmp1 =INT_MAX,k1;
            int n,d,e;
            cin>>n>>d>>e;
            e *= 5;
            int tmp1=n,tmp2=n;
            int i=n/e;
            while(i--){
                if((tmp1%d)<mntmp1)
                    mntmp1 = (tmp1%d);
                tmp1 -= e;
            }
            mntmp1 = min(min(mntmp1,(tmp1%d)),tmp1);
            cout<<mntmp1;
    	}


    #include<bits/stdc++.h>
    using namespace std ;
    #define endl '\n'
    #define lld long long int
    #define ull unsigned long long int
    ull power(ull x, ull y){ull temp;if( y == 0)return 1;temp = power(x, y/2); if (y%2 == 0) return temp*temp;else return x*temp*temp; }
    ull gcdFactor(ull n){ ull tmp=n,res=0;for(ull i=1 ; i*i <=tmp ; i++){if(tmp%i==0){res++;if(tmp/i!=i)res++;}}return res;}
    #define ullmax ULLONG_MAX
    void Solution(void);
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        Solution();
        return 0;
    }

    // The difference between the novice and the master is that the master has failed more than the novice has tried
    // It is not over when you lose it is over when you quit
    // If you have time to think for a beautiful end, then live beautifully until the end

   void Solution(){
        int maxSum =0 , tmpSum =0 ;
        int n,d,e;
        cin>>n>>d>>e;
        e *= 5;
        int tmp1=n,tmp2=n;
        int i=n/e;
        if(i==100)
            i--;
        while(i--){
            if(tmp1>=e){
                tmp1 -= e;
            }else{
                break;
            }
        }
        tmp1 %= d;
        tmp2 = n%d;
        i=tmp2/e;
        if(i==100)
            i--;
        while(i--){
            if(tmp2>=e){
                tmp2 -= e;
            }else{
                break;
            }
        }
        if(tmp1<tmp2){
            cout<<tmp1<<endl;
        }else{
            cout<<tmp2<<endl;
        }
	}


        #include<bits/stdc++.h>
        using namespace std ;
        #define endl '\n'
        #define lld long long int
        #define ull unsigned long long int
        ull power(ull x, ull y){ull temp;if( y == 0)return 1;temp = power(x, y/2); if (y%2 == 0) return temp*temp;else return x*temp*temp; }
        ull gcdFactor(ull n){ ull tmp=n,res=0;for(ull i=1 ; i*i <=tmp ; i++){if(tmp%i==0){res++;if(tmp/i!=i)res++;}}return res;}
        #define ullmax ULLONG_MAX
        void Solution(void);
        int main()
        {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            Solution();
            return 0;
        }

        // The difference between the novice and the master is that the master has failed more than the novice has tried
        // It is not over when you lose it is over when you quit
        // If you have time to think for a beautiful end, then live beautifully until the end

       void Solution(){
            int maxSum =0 , tmpSum =0 ,mntmp1 =INT_MAX , mntmp2=INT_MAX,k1,k2;
            int n,d,e;
            cin>>n>>d>>e;
            e *= 5;
            int tmp1=n,tmp2=n;
            int i=n/e;
            while(i--){
                if(tmp1%d==0){
                    tmp1 = tmp1%d;
                }
                else{
                    tmp1 -= e;
                    k1 = tmp1%d;
                    if(k1<mntmp1)
                        mntmp1 = k1;
                }
            }
            tmp1 %= d;
            i = n/d;
            while(i--){
                if(tmp2%e==0){
                    tmp2 = tmp2%e;
                }
                else{
                    tmp2 -= d;
                    k2 = tmp2%e;
                    if(k2<mntmp2)
                        mntmp2 = k2;
                }
            }
            tmp2 %= e;
            tmp1 = min(mntmp1,tmp1);
            tmp2 = min(mntmp2,tmp2);
            if(tmp1<tmp2){
                cout<<tmp1<<endl;
            }else{
                cout<<tmp2<<endl;
            }
    	}


#include<bits/stdc++.h>
typedef long long ll;

using namespace std;
int main()
{

  ll arr[]={5, 10, 20, 50, 100, 200};  //euro
  ll brr[]={1, 2, 5, 10, 20, 50, 100};   //doll
  ll no,d,n,e;
  cin>>no>>d>>e;
  n=no;
 for(ll i=6;i>=0;i--)
 {
     while(n-d*brr[i]>=0) n=n-d*brr[i];
 }
 for(ll i=5;i>=0;i--)
 {
     while(n-e*arr[i]>=0) n=n-e*arr[i];
 }

 ll k=n;
 n=no;

 for(ll i=5;i>=0;i--)
 {
     while(n-e*arr[i]>=0)  n=n-e*arr[i];

 }
 //cout<<n;
 for(ll i=5;i>=0;i--)
 {
     while(n-d*brr[i]>=0) n=n-d*brr[i];
 }
     //cout<<n<<" "<<k;
     cout<<min(n,k)<<endl;
  return 0;
}


#include<bits/stdc++.h>
typedef long long ll;

using namespace std;
int main()
{
  ll brr[]={1, 2, 5, 10, 20, 50, 100};   //doll
  ll arr[]={5, 10, 20, 50, 100, 200};  //euro
  ll no,d,n,e;
  cin>>no>>d>>e;
  n=no;
 for(ll i=6;i>=0;i--)
 {
     while(n-d*brr[i]>0) n=n-d*brr[i];
 }
 for(ll i=5;i>=0;i--)
 {
     while(n-e*arr[i]>0) n=n-e*arr[i];
 }

 ll k=n;
 n=no;

 for(ll i=5;i>=0;i--)
 {
     while(n-e*arr[i]>0)  n=n-e*arr[i];

 }
 //cout<<n;
 for(ll i=5;i>=0;i--)
 {
     while(n-d*brr[i]>0) n=n-d*brr[i];
 }
     cout<<min(n,k)<<endl;
  return 0;
}


#include<bits/stdc++.h>
typedef long long ll;

using namespace std;
int main()
{

  ll arr[]={5, 10, 20, 50, 100, 200};  //euro
  ll brr[]={1, 2, 5, 10, 20, 50, 100};   //doll
  ll no,d,n=100000000000,e;
  cin>>no>>d>>e;
  for(ll i=1;i*5*e<=no;i++)
  {
      n=min(n,(no-i*5*e)%d);
  }
  cout<<min(n,no%d)<<endl;

  return 0;
}


#include<bits/stdc++.h>
typedef long long ll;

using namespace std;
int main()
{

  ll arr[]={5, 10, 20, 50, 100, 200};  //euro
  ll brr[]={1, 2, 5, 10, 20, 50, 100};   //doll
  ll no,d,n=100000000000,e;
  cin>>no>>d>>e;
  for(ll i=1;i*5*e<=no;i++)
  {
      n=min(n,(no-i*5*e)%d);
  }
  cout<<n<<endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),v.end()
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
 vector<ll> dol={1,2,5,10,20,50,100},euro={5,10,20,50,100,200};
    ll n,d,e;
    cin>>n>>d>>e;
    vector<ll> tmp;
    ll ans=inf;
    for(int i=0;i<7;i++){
       if(i<6){tmp.push_back(dol[i]*d);tmp.push_back(euro[i]*e);}
       else tmp.push_back(dol[i]*d);
    }
     for(int i=0;i<(1<<14);i++){
         ll res=n;
         for(int j=0;j<13;j++){
              if(i&(1<<j))res-=tmp.at(j);
         }
         if(res<0)continue;
         ans=min(ans,res);
     }
   cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
    vector<ll> dol={1,2,5,10,20,50,100},euro={5,10,20,50,100,200};
    ll n,d,e;
    cin>>n>>d>>e;
    ll tmp_df=n,tmp_ef=n;
    while(1){
    for(int i=0;i<7;i++){
        if(dol[0]*d>tmp_df)break;
        if(i>0&&dol[i]*d>tmp_df){tmp_df-=dol[i-1]*d;break;}
        if(i==6&&dol[i]*d<=tmp_df)tmp_df-=dol[i]*d;
    }
    for(int i=0;i<6;i++){
        if(euro[0]*e>tmp_df)break;
        if(i>0&&euro[i]*e>tmp_df){tmp_df-=euro[i-1]*e;break;}
        if(i==5&&euro[i]*e<=tmp_df)tmp_df-=euro[i]*e;
    }
    if(euro[0]*e>tmp_df&&dol[0]*d>tmp_df)break;
}
while(1){
    for(int i=0;i<6;i++){
        if(euro[0]*e>tmp_ef)break;
        if(i>0&&euro[i]*e>tmp_ef){tmp_ef-=euro[i-1]*e;break;}
        if(i==5&&euro[i]*e<=tmp_ef)tmp_ef-=euro[i]*e;
    }
    for(int i=0;i<7;i++){
        if(dol[0]*d>tmp_ef)break;
        if(i>0&&dol[i]*d>tmp_ef){tmp_ef-=dol[i-1]*d;break;}
        if(i==6&&dol[i]*d<=tmp_ef)tmp_ef-=dol[i]*d;
    }
    if(euro[0]*e>tmp_ef&&dol[0]*d>tmp_ef)break;
}
   //cout<<tmp_df<<" "<<tmp_ef<<endl;
    cout<<max((ll)0,min(tmp_df,tmp_ef))<<endl;

}