Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. 

Unfortunately, Igor could only get v liters of paint. He did the math and concluded that digit d requires a_{d} liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number.

Help Igor find the maximum number he can write on the fence.


-----Input-----

The first line contains a positive integer v (0 ≤ v ≤ 10^6). The second line contains nine positive integers a_1, a_2, ..., a_9 (1 ≤ a_{i} ≤ 10^5).


-----Output-----

Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1.


-----Examples-----
Input
5
5 4 3 2 1 2 3 4 5

Output
55555

Input
2
9 11 1 12 5 8 9 10 6

Output
33

Input
0
1 1 1 1 1 1 1 1 1

Output
-1

Difficulty: MEDIUM_HARD

Solutions:
n = int(input())
ar = [int(x) for x in input().split()]
mi = -1
mc = 10 ** 18
for i in range(len(ar)):
	if ar[i] <= mc:
		mc = ar[i]
		mi = i
digits = n // mc
if digits == 0:
	print(-1)
	exit(0)
n -= mc * digits
ar = ar[::-1]
ans = [str(mi + 1)] * digits
index = 0
while index < digits:
	for i in range(len(ar)):
		if 9 - i <= mi + 1:
			print(''.join(ans))
			exit(0)
		if n - ar[i] + mc >= 0:
			n = n - ar[i] + mc
			ans[index] = str(9 - i)
			break
	index += 1
print(''.join(ans))


n = int(input())
l = [*map(int, input().split())]
minim = [10 ** 18, 0]
for i in range(9):
	if l[i] <= minim[0]:
		minim = [l[i], i + 1]
(leng, rem) = divmod(n, minim[0])
if leng == 0:
	print(-1)
	exit()
fin = []
cnt = 0
for i in range(8, minim[1] - 1, -1):
	if rem + minim[0] >= l[i]:
		(tot, rem) = divmod(rem, l[i] - minim[0])
		fin += [str(i + 1)] * tot
		cnt += tot
print(''.join(fin + (leng - cnt) * [str(minim[1])]))


n = int(input())
l = list(map(int, input().split()))
m = min(l)
if n < m:
	print('-1')
elif n % m == 0:
	s = -1
	for i in range(8, -1, -1):
		if l[i] == m:
			s = i + 1
			break
	print(str(s) * int(n / m))
else:
	s = -1
	for i in range(8, -1, -1):
		if l[i] == m:
			s = i + 1
			break
	st = str(s) * int(n / m)
	st = list(st)
	n -= len(st) * m
	j = 8
	index = 0
	while n != 0 and j >= 0 and (index < len(st)):
		if l[j] <= m + n:
			st[index] = str(j + 1)
			index += 1
			n = n + m - l[j]
		else:
			j -= 1
	print(''.join(st))


def colour_the_fence():
	n = int(input())
	litre_list = list(map(int, str(input()).split()))
	paint_dict = {}
	for i in range(1, 10):
		if litre_list[i - 1] > n:
			continue
		paint_dict[litre_list[i - 1]] = i
	min_litre = min(litre_list)
	if min_litre > n:
		print(-1)
	else:
		x = divmod(n, min_litre)
		remaining_litres = x[1]
		largest_num = x[0] * str(paint_dict[min_litre])
		if remaining_litres != 0:
			while remaining_litres > 0:
				replace = find_max(paint_dict, remaining_litres + min_litre)
				if paint_dict[replace] < paint_dict[min_litre] or replace == min_litre:
					break
				else:
					largest_num = largest_num[1:]
					remaining_litres += min_litre
					remaining_litres -= replace
					largest_num = largest_num + str(paint_dict[replace])
		print(''.join(sorted(largest_num, reverse=True)))

def find_max(given_dict, limit):
	max_value = max_key = -1
	for key in given_dict.keys():
		if key <= limit:
			if given_dict[key] > max_value:
				max_value = given_dict[key]
				max_key = key
	return max_key
colour_the_fence()


v = int(input())
l = list(map(int, input().split()))
m = min(l)
r1 = v // m
num = r1
if num == 0:
	print(-1)
else:
	while num:
		for i in range(8, -1, -1):
			if l[i] <= v and (v - l[i]) // m == num - 1:
				v = v - l[i]
				num = num - 1
				print(i + 1, end='')
				break


import os
import io
import sys
from collections import Counter, defaultdict
import math
import random
import heapq as hq
from functools import reduce, cmp_to_key
from collections import deque
import threading
import bisect

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
v = iinput()
a = rlinput()
if min(a) > v:
	print(-1)
else:
	temp = 0
	for i in range(1, 9):
		if a[i] < a[temp]:
			temp = i
	mn = v // a[temp]
	v -= a[temp] * mn
	ans = [temp + 1] * mn
	for i in range(mn):
		for j in range(8, temp, -1):
			if v - a[j] + a[temp] >= 0:
				ans[i] = j + 1
				v -= a[j] - a[temp]
				break
		if v < 0:
			break
	print(''.join(map(str, ans)))


import sys
from copy import deepcopy

class Digit(object):

	def __init__(self, _cost, _value):
		self.cost = _cost
		self.value = _value

def main():
	v = int(input())
	a = list(map(int, input().split()))
	a = tuple((Digit(cost, digit + 1) for (digit, cost) in enumerate(a)))
	low_digit = deepcopy(min(a, key=lambda digit: digit.cost * 10 - digit.value))
	if low_digit.cost > v:
		print(-1)
		return
	digits = v // low_digit.cost
	v -= digits * low_digit.cost
	for i in range(9):
		a[i].cost -= low_digit.cost
	low_digit.cost = 0
	for better in reversed(a):
		if better.cost > 0 and better.value > low_digit.value:
			count = v // better.cost
			v -= count * better.cost
			digits -= count
			print(str(better.value) * count, end='')
	print(str(low_digit.value) * digits)
main()


n = int(input())
Ar = [int(x) for x in input().split()]
A = []
m = min(Ar)
for i in range(9):
	if Ar[i] == m:
		A.append(i + 1)
if m <= n:
	k = n // m
	p = list(str(A[-1]) * k)
	remain = n - k * Ar[A[-1] - 1]
	s = 0
	for i in range(9, A[-1], -1):
		while Ar[i - 1] - Ar[A[-1] - 1] <= remain:
			remain -= Ar[i - 1] - Ar[A[-1] - 1]
			p[s] = str(i)
			s += 1
	print(''.join(p))
else:
	print(-1)


from sys import stdin, stdout
from collections import defaultdict
v = int(input())
l = list(map(int, stdin.readline().split()))
a = min(l)
d = v // a
l1 = []
for i in range(9, 0, -1):
	ans = True
	for j in range(1, d + 1):
		if (v - j * l[i - 1]) // a < d - j:
			v -= (j - 1) * l[i - 1]
			d -= j - 1
			ans = False
			break
		else:
			l1.append(str(i))
	if ans == True:
		break
if len(l1) == 0:
	print(-1)
else:
	l1.sort(reverse=True)
	stdout.write(''.join(l1) + '\n')


def solve(v, a):
	mn = min(a)
	d = v // mn
	if d == 0:
		return None
	r = v % mn
	res = []
	for i in range(d):
		t = 9
		while t >= 1:
			if a[t - 1] <= mn + r:
				break
			t -= 1
		assert t >= 1
		r -= a[t - 1] - mn
		res.append(t)
	return res
v = int(input())
a = list(map(int, input().split()))
res = solve(v, a)
if res:
	print(*res, sep='')
else:
	print(-1)


v = int(input())
a = list(map(int, input().split()))
res = []
mini = min(a)
max_len = v // mini
if max_len == 0:
	print(-1)
else:
	for i in range(max_len, 0, -1):
		for dig in range(9, 0, -1):
			if v - a[dig - 1] >= mini * (i - 1):
				res.append(str(dig))
				v -= a[dig - 1]
				break
	print(''.join(res))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		v = I()
		a = LI()
		r = []
		if all((c > v for c in a)):
			r.append(-1)
		else:
			m = inf
			mi = 0
			for (i, c) in enumerate(a):
				if m > c:
					m = c
					mi = i
			r = [mi + 1] * (v // m)
			v %= m
			rl = len(r)
			ri = 0
			for i in range(8, mi, -1):
				t = a[i] - m
				while ri < rl and v >= t:
					r[ri] = i + 1
					ri += 1
					v -= t
		rr.append(JA(r, ''))
	return JA(rr, '\n')
print(main())


def index(a, lis):
	cur = -1
	for i in range(len(lis)):
		if lis[i] == a:
			cur = i
	return cur
import sys
n = int(input())
lis = [int(x) for x in input().split()]
minn = min(lis)
ind = index(minn, lis)
leng = n // minn
if leng == 0:
	print(-1)
	sys.exit()
n = n % minn
for i in range(9):
	lis[i] = lis[i] - minn
mem = dict()
for i in range(8, -1, -1):
	if lis[i] == 0:
		break
	mem[i] = n // lis[i]
	n = n % lis[i]
	if n == 0:
		break
tot = sum(mem.values())
ans = ''
for item in mem:
	ans = ans + str(item + 1) * mem[item]
ans = ans + str(ind + 1) * (leng - tot)
print(ans)


n = int(input())
a = list(map(int, input().split()))
m = a[0]
d = 1
for i in range(9):
	if a[i] <= m:
		m = a[i]
		d = i + 1
if m > n:
	print(-1)
	exit()
ans = list(str(d) * (n // m))
rem = n - m * (n // m)
for i in range(len(ans)):
	if rem <= 0:
		break
	for j in range(8, d - 1, -1):
		if a[j] - a[d - 1] <= rem:
			ans[i] = str(j + 1)
			rem -= a[j] - a[d - 1]
			break
print(''.join(ans))


nPaint = int(input())
cost = [1 << 35] + list(map(int, input().split()))
sz = nPaint // min(cost)
if not sz:
	print(-1)
	exit()
cur = 0
for dig in range(1, 10):
	if nPaint // cost[dig] == sz:
		cur = dig
		break
ret = [cur] * sz
rem = nPaint - cost[cur] * sz
for i in range(sz):
	cur = ret[i]
	best = None
	for dig in range(cur + 1, 10):
		if rem + cost[cur] >= cost[dig]:
			best = dig
	if best:
		ret[i] = best
		rem += cost[cur] - cost[best]
print(''.join(map(str, ret)))


import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int, input().split()))
c = 0
x = len(l)
w = ''
zzz = 0
q = 0
mi = min(l)
q = l.index(min(l))
if n // min(l) == 0:
	print(-1)
else:
	l1 = [0] * (n // min(l))
	aa = n // mi - 1
	cc = 0
	for i in range(len(l1)):
		for j in range(8, q - 2, -1):
			if aa * mi + l[j] + cc <= n:
				aa -= 1
				cc += l[j]
				l1[i] = str(j + 1)
				break
	k = ''.join(l1)
	print(k)


n = int(input())
cost = list(map(int, input().split()))
if n < min(cost):
	print(-1)
else:
	min_cost = min(cost)
	digits = n // min_cost
	extra = n - digits * min_cost
	ans = [9 - list(reversed(cost)).index(min_cost)] * digits
	idx = 0
	while extra > 0 and idx < len(ans):
		found = False
		for i in range(9):
			if extra >= cost[i] - min_cost:
				largest = i
				found = True
		if not found:
			break
		extra -= cost[largest] - min_cost
		ans[idx] = largest + 1
		idx += 1
	print(''.join((str(i) for i in ans)))


v = int(input())
l = [int(k) for k in input().split(' ')]
mi = min(l)
if mi > v:
	print(-1)
	quit()
if mi == max(l) or mi == l[8]:
	print('9' * int(v / l[8]))
	quit()
dig = [int(v / l[i]) for i in range(9)]
maxind = 0
maxx = max(dig)
for i in range(9):
	if dig[8 - i] == maxx:
		maxind = 9 - i
		break
num = str(maxind) * dig[maxind - 1]
vcopy = v
num2 = ''
if '9' not in num:
	for i in range(9, 0, -1):
		if l[i - 1] == mi:
			num2 += str(i) * (len(num) - len(num2))
			print(num2)
			quit()
		while vcopy >= l[i - 1] and vcopy - l[i - 1] >= mi * (len(num) - len(num2) - 1):
			num2 += str(i)
			vcopy -= l[i - 1]
print(num2 if int('0' + num2) > int(num) else num)


n = int(input())
arr = list(map(int, input().split()))
d = {}
for (i, c) in enumerate(arr):
	d[c] = max(d.get(c, 0), i + 1)
m = min(d.keys())
k = n // m
y = n % m
if n < m:
	print(-1)
else:
	ans = [d[min(d.keys())]] * k
	for key in sorted(d.keys(), key=lambda x: -d[x]):
		while m <= key <= m + y and d[key] > ans[-1]:
			ans = [d[key]] + ans
			ans.pop()
			y -= key - m
	ans.sort(reverse=True)
	print(''.join(map(str, ans)))


v = int(input())
d = list(map(int, input().split()))
digit_mapping = []
for i in range(1, 10):
	digit_mapping.append((d[i - 1], i))
digit_mapping.sort()
if digit_mapping[0][0] > v:
	print(-1)
else:
	i = 0
	minimum = digit_mapping[i][0]
	while i < 9 and digit_mapping[i][0] == minimum:
		i += 1
	i -= 1
	number = [digit_mapping[i][1]] * int(v // digit_mapping[i][0])
	paint_left = v - v // digit_mapping[i][0] * digit_mapping[i][0]
	j = 0
	for i in range(8, -1, -1):
		if d[i] - minimum <= paint_left:
			while j < len(number) and d[i] - minimum <= paint_left:
				number[j] = i + 1
				paint_left -= d[i] - minimum
				j += 1
	print(''.join([str(num) for num in number]))


import sys
v = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
ind = 1
ind = 1
vol = A[0]
for i in range(1, 10):
	if A[i - 1] < vol:
		vol = A[i - 1]
		ind = i
	elif A[i - 1] == vol and i > ind:
		vol = A[i - 1]
		ind = i
used = v // vol * vol
rest = v - used
x = rest - 1
z = 0
ans = list(str(ind) * (v // vol))
while len(ans) != 0 and x != rest and (z < len(ans)):
	x = rest
	for i in range(9, 0, -1):
		if A[i - 1] - A[ind - 1] <= rest:
			rest -= A[i - 1] - A[ind - 1]
			ans[z] = str(i)
			z += 1
			break
Ans = ''
for item in ans:
	Ans += item
if len(Ans) == 0:
	print(-1)
else:
	sys.stdout.write(Ans)


paint = input()
numbers = input().split(' ')

def number(numbers, paint):
	min = 1
	i = 1
	while int(i < 10):
		if int(numbers[-i]) < int(numbers[-min]):
			min = int(i)
		i += 1
	cheaper = int(paint) // int(numbers[-min])
	if int(cheaper) == 0:
		return -1
	extra = int(paint) % int(numbers[-min])
	number = ''
	i = 1
	while int(i) < int(min) and int(extra) > 0:
		if int(numbers[-i]) - int(numbers[-min]) <= int(extra):
			extra -= int(numbers[-i]) - int(numbers[-min])
			number = str(number) + str(10 - i)
			cheaper -= 1
			i = 1
		else:
			i += 1
	return str(number) + str(10 - min) * int(cheaper)
print(number(numbers, paint))


v = int(input())
a = [-1] + list(map(int, input().split()))
q = [0] * 10
if v < min(a[1:]):
	print(-1)
else:
	top_digit = -1
	for i in range(1, 10):
		if a[i] == min(a[1:]):
			top_digit = i
	q[top_digit] = v // a[top_digit]
	rem = v % a[top_digit]
	for i in range(9, top_digit, -1):
		if a[i] - a[top_digit] <= rem:
			add = min(rem // (a[i] - a[top_digit]), q[top_digit])
			q[i] += add
			q[top_digit] -= add
			rem = rem - add * (a[i] - a[top_digit])
	print(''.join([str(i) * q[i] for i in range(9, 0, -1)]))


n = int(input())
lis = list(map(int, input().split()))
aa = lis.index(min(lis)) + 1
a = min(lis)
no = list(str(aa) * (n // a))
if len(no) == 0:
	print(-1)
	exit()
dig = n // a
n -= dig * a
for i in range(dig):
	ss = 0
	for j in range(8, aa - 1, -1):
		if n + lis[int(no[i]) - 1] - lis[j] >= 0:
			n += lis[int(no[i]) - 1] - lis[j]
			no[i] = str(j + 1)
			ss = 1
			break
	if ss == 0:
		break
print(''.join(no))


v = int(input())
digits = [int(i) for i in input().split()]
(m, ind) = (digits[0], 0)
for i in range(1, 9):
	if digits[i] <= m:
		(m, ind) = (digits[i], i)
number = str(ind + 1) * (v // m)
l = len(number)
if l == 0:
	print(-1)
else:
	cost = l * m
	for i in range(l):
		for j in reversed(list(range(ind + 1, 9))):
			if v - cost + m >= digits[j]:
				number = number[:i] + str(j + 1) + number[i + 1:]
				cost = cost - m + digits[j]
				break
	print(number)


v = int(input())
arr = list(map(int, input().split()))
max_digits = max([v // x for x in arr])
smallest_v = min(arr)
ans = list()
if max_digits == 0:
	print(-1)
	exit()
for digit in range(8, -1, -1):
	while max_digits > 0:
		if (max_digits - 1) * smallest_v + arr[digit] <= v:
			v -= arr[digit]
			ans.append(digit + 1)
			max_digits -= 1
		else:
			break
print(''.join(map(str, ans)))


import sys

def get_inpL():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_inp():
	return map(int, sys.stdin.readline().strip().split())
t = 1
for _ in range(t):
	v = int(input())
	a = get_inpL()
	m = int(1000000.0)
	ind = 0
	for i in range(len(a)):
		if a[i] <= m:
			m = a[i]
			ind = i
	count = int(v / m)
	rem = int(v % m)
	if count == 0:
		print(-1)
	for i in range(len(a) - 1, -1, -1):
		while count > 0 and a[i] - a[ind] <= rem:
			print(i + 1, end='')
			count = count - 1
			rem = rem - (a[i] - a[ind])


n = int(input())
arr = list(map(int, input().split()))
m = min(arr)
ind = [i for (i, j) in enumerate(arr) if j == m][-1]
cnt = [0] * 11
cnt[ind + 1] = n // m
rem = n % m
while cnt[ind + 1] > 0:
	rem += m
	var = [i for (i, j) in enumerate(arr) if m < j <= rem and i > ind]
	if var:
		cnt[ind + 1] -= 1
		cnt[var[-1] + 1] += 1
		rem -= arr[var[-1]]
	else:
		break
if cnt[ind + 1]:
	for i in range(9, 0, -1):
		print(str(i) * cnt[i], end='')
else:
	print(-1)


n = int(input())
a = list(map(int, input().rstrip().split()))
h = min(a)
index = a.index(h)
if sum(a) == n:
	print('987654321')
	exit()
if n < h:
	print(-1)
else:
	for i in range(8, -1, -1):
		if a[i] == h:
			index = i + 1
			break
	ans = str(index) * (n // a[index - 1])
	ans = [int(i) for i in ans]
	remaining = n - n // a[index - 1] * a[index - 1]
	for i in range(len(ans)):
		total = remaining + a[index - 1]
		for j in range(8, -1, -1):
			if a[j] <= total:
				total -= a[j]
				ans[i] = j + 1
				remaining = total
				break
	print(''.join((str(e) for e in ans)))


v = int(input())
a = list(map(int, input().split()))
m = list(enumerate(a, 1))
k = sorted(m, key=lambda x: (-x[1], x[0]))[-1]
t = v // k[1]
v -= t * k[1]
num = [k[0]] * t
for i in range(t):
	if v + k[1] > min(a):
		num[i] = list((q for q in m if q[1] <= v + k[1]))[-1][0]
		v -= a[num[i] - 1] - k[1]
	else:
		break
print(''.join(map(str, num)) or -1)


v = int(input())
a = list(map(int, input().split()))
import sys
ans = []
mini = sys.maxsize
for i in range(8, -1, -1):
	if a[i] < mini:
		mini = a[i]
		ind = i
if v < mini:
	print('-1')
else:
	n = v // mini
	ans = [ind + 1] * n
	v = v % mini
	i = 0
	while v > 0 and i < n:
		v = v + mini
		for j in range(8, ind - 1, -1):
			if a[j] <= v:
				ans[i] = j + 1
				v = v - a[j]
				break
		i += 1
	print(''.join([str(elem) for elem in ans]))


def main():
	n = int(input())
	l = [int(i) for i in input().split()]
	m = [max(l), 0]
	pos = 0
	for (i, v) in enumerate(l):
		if v <= m[0]:
			m = [v, str(i + 1)]
	max_digits = n // m[0]
	resto = n - max_digits * m[0]
	if not max_digits:
		print(-1)
		return
	for i in range(max_digits):
		v = -1
		for num in range(int(m[1]), 9):
			if resto >= l[num] - m[0]:
				v = num
		if v == -1:
			print(m[1] * (max_digits - i))
			break
		else:
			resto -= l[v] - m[0]
			print(v + 1, end='')
	else:
		print()
main()


v = int(input())
costs = list(map(int, input().split()))
min_cost = min(costs)
max_cost = max(costs)
digit = -1
for (i, c) in enumerate(costs):
	if c == min_cost and i + 1 >= digit:
		digit = i + 1
length = v // min_cost
number = [digit] * length
leftover = v % min_cost
change_costs = [c - min_cost if c != min_cost else max_cost for c in costs]
position = 0
for digit in range(9, digit, -1):
	change_cost = change_costs[digit - 1]
	while leftover >= change_cost:
		number[position] = digit
		position += 1
		leftover -= change_cost
if len(number) == 0:
	print(-1)
else:
	for digit in number:
		print(digit, end='')


import sys

def _(f):
	for l in f:
		for i in l.split():
			yield int(i)
g = _(sys.stdin)
v = next(g)
ar = []
for i in range(9):
	ar.append((next(g), i + 1))
dominant = min(ar, key=lambda t: (t[0], -t[1]))
digits = v // dominant[0]
v -= dominant[0] * digits
ar = [(a - dominant[0], n) for (a, n) in ar if a > dominant[0] and n > dominant[1]]
ar.sort(key=lambda x: (-x[1], x[0]))
print(ar, file=sys.stderr)
s = ''
for (a, n) in ar:
	if a <= v:
		q = v // a
		v -= q * a
		s += str(n) * q
s = '%s%s' % (s, str(dominant[1]) * (digits - len(s)))
if s:
	print(s)
else:
	print(-1)


import sys
input = sys.stdin.buffer.readline

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

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
v = int(input())
a = I()
mina = min(a)
l = v // mina
if l == 0:
	print(-1)
else:
	for i in reversed(range(9)):
		if a[i] == mina:
			break
	left = v - l * mina
	m = i + 1
	currans = [i + 1] * l
	for i in range(l):
		for j in reversed(range(m + 1, 10)):
			if left >= a[j - 1] - mina:
				left -= a[j - 1] - mina
				currans[i] = j
				break
	print(''.join([str(i) for i in currans]))


n = int(input())
l = list(map(int, input().split()))
if min(l) > n:
	print(-1)
else:
	m = min(l)
	ind = -1
	for i in range(0, 9):
		if l[i] == m:
			ind = i
	a = [ind + 1] * (n // m)
	lo = n % m
	f = True
	ci = 0
	while lo != 0 and f:
		if ci == len(a):
			break
		for i in range(8, -1, -1):
			if l[i] <= lo + m:
				if i < ind:
					f = False
				else:
					a[ci] = i + 1
					ci += 1
					lo = lo + m - l[i]
					break
	print(''.join(map(str, a)))


import sys
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 8
n = int(ri())
a = Ri()
a = [INF] + a
minn = min(a)
no = -1
for i in range(9, 0, -1):
	if minn == a[i]:
		no = i
		break
digs = n // minn
ans = [str(no) for i in range(digs)]
n -= digs * minn
for i in range(digs):
	for j in range(9, 0, -1):
		if n + minn - a[j] >= 0:
			n = n + minn - a[j]
			ans[i] = str(j)
			break
if len(ans) == 0:
	print(-1)
else:
	print(''.join(ans))


3

def readln():
	return tuple(map(int, input().split()))
(n,) = readln()
a = readln()
m = min(a)
ind = [i for (i, _) in enumerate(a) if _ == m][-1]
cnt = [0] * 11
cnt[ind + 1] = n // m
ost = n % m
while cnt[ind + 1] > 0:
	ost += m
	var = [i for (i, _) in enumerate(a) if m < _ <= ost and i > ind]
	if var:
		cnt[ind + 1] -= 1
		cnt[var[-1] + 1] += 1
		ost -= a[var[-1]]
	else:
		break
if cnt[ind + 1]:
	for i in range(9, 0, -1):
		print(str(i) * cnt[i], end='')
	print()
else:
	print(-1)


from sys import stdout

def compare(s1, s2):
	if len(s1) > len(s2):
		return True
	elif len(s1) < len(s2):
		return False
	else:
		i = 0
		while i < len(s1):
			if int(s1[i]) > int(s2[i]):
				return True
			elif int(s1[i]) < int(s2[i]):
				return False
			i += 1
		return True

def combine(num, left):
	total = left // ls[num - 1]
	if total == 0:
		return ''
	left1 = left - total * ls[num - 1]
	i = 0
	ans = [0] * 9
	ans[num - 1] += total
	while i < total and left1 > 0:
		for j in range(9, 0, -1):
			if j < num:
				break
			if left1 - (ls[j - 1] - ls[num - 1]) >= 0:
				left1 -= ls[j - 1] - ls[num - 1]
				ans[num - 1] -= 1
				ans[j - 1] += 1
				break
		i += 1
	s = ''
	for i in range(8, -1, -1):
		s += str(i + 1) * ans[i]
	return s
v = int(input())
ls = list(map(int, input().split()))
ans = ''
for i in range(9):
	temp1 = combine(i + 1, v)
	if compare(temp1, ans):
		ans = temp1
if ans == '':
	print(-1)
else:
	stdout.write(ans)


v = int(input())
litres = list(map(int, input().split()))
mn = min(litres)
if mn > v:
	print(-1)
else:
	mx_dig = v // mn
	mx_no = ''
	for dig in range(1, mx_dig + 1):
		use = 9
		while v - litres[use - 1] < (mx_dig - dig) * mn:
			use -= 1
		if litres[use - 1] == mn:
			break
		v -= litres[use - 1]
		mx_no += str(use)
	print(mx_no + str(use) * (mx_dig - dig + 1))


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
if n < min(l):
	print(-1)
	exit()
mm = min(l)
for i in range(8, -1, -1):
	if l[i] == mm:
		mm = i
		break
ans = [mm] * (n // min(l))
r = n - n // min(l) * min(l)
for i in range(len(ans)):
	r = l[ans[i]] + r
	for j in range(8, -1, -1):
		if l[j] <= r:
			ans[i] = j
			r -= l[j]
			break
	if r == 0:
		break
for i in ans:
	print(i + 1, end='')


v = int(input())
a = list(map(int, input().split()))
i = 0
for j in range(1, 9):
	if a[j] <= a[i]:
		i = j
if v // a[i] == 0:
	print(-1)
else:
	length = v // a[i]
	b = v // a[i] * a[i]
	ans = []
	while v >= b:
		j = 8
		while j > i:
			if v >= b + a[j] - a[i]:
				break
			j -= 1
		if j == i:
			break
		b += a[j] - a[i]
		ans += [j + 1]
	print(''.join(map(str, ans + [i + 1] * (length - len(ans)))))


import math
import sys
n = int(input())
d = list(map(int, input().split()))
if n < min(d):
	exit(print(-1))
min = d[0]
t = 0
for i in range(1, 9):
	if d[i] <= min:
		t = i
		min = d[i]
ans = [t for i in range(n // d[t])]
n = n - d[t] * (n // d[t])
for i in range(len(ans)):
	for j in range(ans[i] + 1, 9):
		if d[j] <= n + d[ans[i]]:
			n = n + d[ans[i]] - d[j]
			ans[i] = j
print(''.join([str(i + 1) for i in ans]))


v = int(input())
cc = [int(x) for x in input().split(' ')]
(l, a, f, q, n, m) = (0, 0, 0, 0, 9, 10000000)
ans = ''
for i in range(9):
	if cc[i] <= m:
		(m, a) = (cc[i], i)
l = v // cc[a]
v -= l * cc[a]
if l == 0:
	print(-1)
	f = 1
res = l * str(a + 1)
if f == 0:
	l = len(res)
	for i in range(l):
		a = int(res[i])
		for j in range(9, a, -1):
			if cc[j - 1] <= v + cc[a - 1]:
				v += cc[a - 1]
				v -= cc[j - 1]
				res = res[0:i] + str(j) + res[i + 1:]
				break
	print(res)


v = int(input())
arr = list(map(int, input().split()))
mm = min(arr)
ii = arr.index(mm)
if v // mm == 0:
	print(-1)
	exit()
cc = v // mm
xx = v % mm
ans = ''
for i in range(cc):
	lol = ii
	for j in range(8, ii, -1):
		if arr[j] - arr[lol] <= xx:
			xx -= arr[j] - arr[lol]
			lol = j
			break
	print(lol + 1, end='')
print()


def main():
	v = int(input())
	l = list(((w, 9 - d) for (d, w) in enumerate(map(int, input().split()))))
	(w, d0) = min(l)
	le = v // w
	if not le:
		print(-1)
		return
	res = [str(10 - d0)] * le
	v -= w * le
	(base, start) = (w, 0)
	l = sorted(((10 - d, w - base) for (w, d) in l if d < d0))
	while l:
		(d, w) = l.pop()
		delta = v // w
		res[start:start + delta] = [str(d)] * delta
		start += delta
		v -= w * delta
	print(''.join(res))

def __starting_point():
	main()
__starting_point()


n = int(input())
a = [int(i) for i in input().split()]
m = n
mi = -1
q = 0
for i in range(9):
	if a[i] <= m:
		m = a[i]
		mi = i
if mi == -1:
	print('-1')
else:
	x = n // m
	n = n % m + m
	for j in range(x):
		f = 0
		for i in range(8, mi, -1):
			if a[i] <= n and f == 0:
				n = n - a[i]
				print(i + 1, end='')
				q += 1
				f = 1
		n += m
		if f == 0:
			break
	print(''.join(str(mi + 1) * (x - q)))


from sys import exit
lit = int(input())
cost = list(map(int, input().split()))
st = list()
while lit >= min(cost):
	min1 = 0
	for i in range(len(cost)):
		if cost[min1] >= cost[i]:
			min1 = i
	lit -= cost[min1]
	st.append(str(min1 + 1))
if len(st) <= 0:
	print('-1')
	exit(0)
for i in range(len(st)):
	c = cost[int(st[i]) - 1]
	for j in range(8, int(st[i]) - 1, -1):
		if lit - cost[j] + c >= 0:
			lit -= cost[j]
			lit += c
			st[i] = str(j + 1)
			break
	if lit == 0:
		break
print(*st, sep='')


from sys import stdin
input = stdin.readline

def color(v, arr):
	if arr[8] == min(arr) and v != 0:
		return '9' * (v // arr[8])
	ans = ''
	for i in range(len(arr)):
		d = v // arr[i]
		if d > len(ans):
			ans = str(i + 1) * d
	if ans == '':
		return -1
	l = len(ans)
	m = arr[int(ans[0]) - 1]
	k = v - l * m
	curr = ''
	c = 0
	while c < l:
		for i in range(len(arr) - 1, -1, -1):
			if arr[i] <= k + m:
				curr += str(i + 1)
				k += m
				k -= arr[i]
				c += 1
				break
	return max(ans, curr)
a = int(input())
lst = list(map(int, input().strip().split()))
print(color(a, lst))


from math import *
from itertools import *
from collections import *
from bisect import *
v = int(input())
A = [(i + 1, int(x)) for (i, x) in enumerate(input().split())]
A.sort(key=lambda x: (x[1], -x[0]))
length = v // A[0][1]
if length == 0:
	print(-1)
else:
	v -= length * A[0][1]
	ans = [A[0][0]] * length
	m = A[0][1]
	A = list(map(lambda x: (x[0], x[1] - m), A))
	A.sort(reverse=True)
	for i in range(length):
		ok = False
		for (digit, val) in A:
			if val <= v:
				ans[i] = digit
				v -= val
				ok = True
				break
		if not ok:
			break
	print(''.join([str(i) for i in ans]))


v = int(input())
a = [int(t) for t in input().split(' ')]
min_cost = min(a)
cheapest_digit = 0
for i in range(9):
	if a[i] == min_cost:
		cheapest_digit = i
number_len = v // min_cost
if number_len == 0:
	print(-1)
else:
	rem = v - number_len * min_cost
	prefix = []
	while rem > 0:
		for i in range(8, cheapest_digit, -1):
			dcost = a[i] - min_cost
			if dcost <= rem:
				rem -= dcost
				prefix.append(str(i + 1))
				number_len -= 1
				break
		else:
			break
	print(''.join(prefix) + str(cheapest_digit + 1) * number_len)


import math
from collections import defaultdict

def search(target):
	for i in range(9, 0, -1):
		if Dict1[i] <= target:
			return i
v = int(input())
arr = [int(i) for i in input().split()]
Dict = defaultdict(int)
Dict1 = defaultdict(int)
if v == 0:
	print(-1)
else:
	for i in range(len(arr)):
		Dict[arr[i]] = max(Dict[arr[i]], i + 1)
		Dict1[i + 1] = arr[i]
	values = list(Dict.keys())
	values.sort()
	ans = str(Dict[values[0]]) * (v // values[0])
	rem = v - len(ans) * values[0]
	if rem > 0:
		s1 = ''
		temp = []
		for i in range(len(values)):
			temp.append((values[i], Dict[values[i]]))
		temp.sort()
		for i in range(len(ans)):
			x = search(rem + values[0])
			s1 += str(x)
			rem = rem + values[0] - Dict1[x]
		ans = s1
	if len(ans) == 0:
		print(-1)
	else:
		print(ans)


v = int(input())
arr = list(map(int, input().split()))
max_lenth = v // min(arr)
ind = arr.index(min(arr))
rem = v % min(arr)
if v < min(arr):
	print(-1)
	exit()
f = 0
for i in range(max_lenth):
	local = ind
	for j in range(8, ind, -1):
		if arr[j] - arr[ind] <= rem:
			rem -= arr[j] - arr[ind]
			local = j
			f = 1
			break
	if f == 0:
		print(str(ind + 1) * max_lenth)
		exit()
	else:
		print(local + 1, end='')


v = int(input())
a = list(map(int, input().split()))
m = min(a)
if v < m:
	print(-1)
	exit()
k = v // m
ans = []
for i in range(k):
	for d in range(8, -1, -1):
		if v - a[d] >= (k - i - 1) * m:
			v -= a[d]
			ans.append(d + 1)
			break
print(''.join(map(str, ans)))


n = int(input())
a = list(map(int, input().split()))
b = a
min_el = min(a)
minIndex = a.index(min(a))
for i in range(minIndex + 1, 9):
	if a[i] == min_el:
		minIndex = i
c = int(n / min_el)
k = n - c * min_el
for i in range(9):
	a[i] -= min_el
T = [0 for i in range(9)]
for i in range(9):
	if a[8 - i] == 0:
		T[i] = c
		break
	T[i] = int(k / a[8 - i])
	c -= T[i]
	k -= T[i] * a[8 - i]
if c < 1:
	print(-1)
else:
	for i in range(9):
		for j in range(T[i]):
			print(9 - i, end='')


v = int(input())
lis = list(map(int, input().split()))
proverka = 0
if v == 0 or v < min(lis):
	print(-1)
	exit(0)
best = 1000000000
for i in range(len(lis) - 1, -1, -1):
	if lis[i] < best:
		best = lis[i]
		ind = i + 1
st = []
while True:
	if v - best < 0:
		break
	else:
		st.append(ind)
	v -= best
for i in range(len(st)):
	st[i] = int(st[i])
for i in range(len(st)):
	if v == 0:
		break
	v += best
	for s in range(len(lis)):
		if v > lis[s]:
			proverka += 1
	if proverka == 0:
		break
	proverka = 0
	for j in range(len(lis) - 1, -1, -1):
		if v >= lis[j] and j + 1 >= st[i]:
			st[i] = j + 1
			v -= lis[j]
print(''.join(map(str, st)))


n = int(input())
a = list(map(int, input().split()))[::-1]
x = min(a)
ans = ''
if n < x:
	exit(print(-1))
else:
	y = n % x
	i = 0
	co = 1
	while y and co > 0:
		co = 0
		while i < a.index(x):
			if y + x >= a[i]:
				y -= a[i] - x
				ans += str(9 - a.index(a[i]))
				n -= a[i]
				i = 0
				co += 1
			else:
				i += 1
	ans += str(9 - a.index(x)) * (n // x)
print(ans)


v = int(input())
a = list(map(int, input().split()))
m = min(a)
if v < m:
	print(-1)
elif v % m == 0:
	print(str(9 - a[::-1].index(m)) * (v // m))
else:
	l = v // m
	v %= m
	s = list(map(int, list(str(9 - a[::-1].index(m)) * l)))
	a = [x - m for x in a]
	for i in range(l):
		if v >= min(a):
			for j in range(8, -1, -1):
				if a[j] <= v and j >= s[i]:
					s[i] = j + 1
					v -= a[j]
					break
			else:
				break
	print(''.join(map(str, s)))


n = int(input())
a = list(map(int, input().split()))
a = a[::-1]
s = ''
b = a[:]
c = []
count = 1
for i in set(b):
	c.append(i)
c.sort()
if n < c[0]:
	print(-1)
else:
	i = 0
	r = n % c[0]
	while r > 0 and count > 0:
		count = 0
		while i < a.index(c[0]):
			if c[0] + r >= a[i]:
				count += 1
				r -= a[i] - c[0]
				s += str(9 - a.index(a[i]))
				n -= a[i]
				i = 0
				continue
			i += 1
	s += n // c[0] * str(9 - a.index(c[0]))
	print(s)


v = int(input())
a = list(map(int, input().split()))
m = 0
for i in range(1, 9):
	if a[i] < a[m]:
		m = i
if a[m] > v:
	print(-1)
	exit()
x = v // a[m]
o = [m + 1] * x
v -= x * a[m]
for i in range(x):
	for j in range(o[i], 9):
		if v - a[j] + a[o[i] - 1] >= 0:
			v = v - a[j] + a[o[i] - 1]
			o[i] = j + 1
print(''.join(map(str, o)))


R = lambda : map(int, input().split())
n = int(input())
arr = list(R())
(md, mc) = min(enumerate(arr), key=lambda x: (x[1], -x[0]))
md += 1
bs = [md] * (n // mc)
rem = n % mc
for i in range(len(bs)):
	for d in range(9, 0, -1):
		if rem >= arr[d - 1] - mc:
			bs[i] = d
			rem -= arr[d - 1] - mc
			break
print(''.join(map(str, bs)) if bs else -1)


import math
start = int(input())
costs = list(map(int, input().split()))
scosts = [(x + 1, costs[x]) for x in range(len(costs))]
scosts.sort(reverse=True)
mincost = scosts[0][1]
minnum = scosts[0][0]
for (val, cost) in scosts:
	if cost < mincost:
		mincost = cost
		minnum = val
best = [minnum for x in range(start // mincost)]
rem = start - start // mincost * mincost
for i in range(len(best)):
	changed = False
	for (val, cost) in scosts:
		if val > best[i] and cost - mincost <= rem:
			rem += mincost
			rem -= cost
			best[i] = val
			changed = True
			break
	if not changed:
		break
if len(best) == 0:
	print(-1)
else:
	ans = ''
	for val in best:
		ans += str(val)
	print(ans)


v = int(input())
A = list(map(int, input().strip().split()))
m = min(A)
R = []
if v < m:
	print(-1)
else:
	for i in range(len(A)):
		if A[i] == m:
			p = i + 1
	R = [p] * int(v // m)
	left = v % m
	up = 1
	p1 = 0
	while left > 0 and up == 1:
		up = 0
		for i in range(len(A) - 1, 0, -1):
			if A[i] - m <= left and i + 1 > p:
				up = 1
				R[p1] = i + 1
				left = left - (A[i] - m)
				p1 += 1
				break
	print(''.join([str(x) for x in R]))


v = int(input())
a = [int(x) for x in input().split()]
if v < min(a):
	print(-1)
	exit()
d = {a[x]: x for x in range(9)}
tmp = 0
for (x, y) in sorted(d.items()):
	if y < tmp:
		del d[x]
	else:
		tmp = y
s = sorted(d.keys())
m = s[0]
digits = v // m
left = v - digits * m
number = [m] * digits
if s == []:
	exit()
for i in range(digits):
	if left == 0:
		break
	while len(s) > 0 and left < s[-1] - number[i]:
		del s[-1]
	if len(s) == 0:
		break
	left -= s[-1] - number[i]
	number[i] = s[-1]
r = ''.join([str(d[x] + 1) for x in number])
print(r)


v = int(input())
a = list(map(int, input().split()))
m = min(a)
n = v // m
if n == 0:
	print(-1)
	exit()
for i in range(9):
	if a[i] == m:
		d = i + 1
res = [d] * n
v -= n * m
for i in range(n):
	temp = -1
	for j in range(d, 9):
		if a[j] <= v + m:
			temp = j
	if temp != -1:
		res[i] = temp + 1
		v -= a[temp] - m
print(''.join(map(str, res)))


def f(t, k, d):
	j = k - 1
	for i in range(k, 9):
		if d >= t[i]:
			j = i
	return (d - t[j], j + 1)
n = int(input())
t = list(map(int, input().split()))
(m, k) = (t[0], 1)
for (i, x) in enumerate(t, 1):
	if x <= m:
		(m, k) = (x, i)
if n < m:
	print(-1)
else:
	(d, j, s) = (n % m, k + 1, [])
	while j != k:
		(d, j) = f(t, k, d + m)
		s.append(j)
	print(''.join(map(str, s)) + str(k) * (n // m - len(s)))


n = int(input())
a = [*map(int, input().split())]
x = a[-1]
p = 9
for i in range(7, -1, -1):
	if a[i] < x:
		x = a[i]
		p = i + 1
if x > n:
	print(-1)
	exit(0)
ans = list(str(p) * (n // x))
n = n % x
for i in range(len(ans)):
	if n <= 0:
		break
	for j in range(8, p - 1, -1):
		if a[j] - a[p - 1] <= n:
			ans[i] = str(j + 1)
			n -= a[j] - a[p - 1]
			break
print(''.join(ans))


v = int(input())
a = list(map(int, input().split()))
new_a = []
a_ind = []
i = 0
while i < 9:
	mm = min(a[i:])
	new_a.append(mm)
	j = 8
	while j >= i:
		if a[j] == mm:
			i = j
			a_ind.append(j)
			break
		j -= 1
	i += 1
i = 0
l = v // new_a[0]
ans = [a_ind[0] + 1] * l
v = v - new_a[0] * l
ind = 0
r = len(new_a) - 1
if v > 0:
	while r > 0:
		if v >= new_a[r] - new_a[0]:
			for i in range(ind, min(ind + v // (new_a[r] - new_a[0]), len(ans))):
				ans[i] = a_ind[r] + 1
			v -= (new_a[r] - new_a[0]) * (v // (new_a[r] - new_a[0]))
			ind = i + 1
		r -= 1
s = ''.join(map(str, ans))
if s == '':
	print(-1)
else:
	print(s)


n = int(input())
l = [(0, 0)] + [(i + 1, int(j)) for (i, j) in enumerate(input().split())]
l.sort(key=lambda x: x[1])
minn = l[1][1]
no = l[1][0]
l.sort()
dig = n // minn
if dig == 0:
	print(-1)
	quit()
rem = n - dig * minn
r = 9
ans = []
for i in range(dig):
	num = l[1][0]
	while True:
		if r <= num:
			break
		zz = l[r][1] - minn
		if rem >= zz:
			rem -= zz
			num = r
			break
		r -= 1
	ans.append(num)
print(*ans, sep='')


import math
v = int(input())
arr = list(map(int, input().split()))

def find_index(arr):
	minn = math.inf
	for i in range(len(arr)):
		if arr[i] <= minn:
			minn = arr[i]
			index = i
	return index

def find_optimal(v, arr):
	index = -1
	for i in range(len(arr)):
		if v >= arr[i]:
			index = i
		else:
			break
	return index
index = find_index(arr)
j = index
length = v // arr[index]
num = ''
num += str(index + 1) * length
v -= arr[index] * length
i = 0
num = list(num)
for i in range(length):
	for k in range(len(arr) - 1, index, -1):
		if v + arr[j] - arr[k] >= 0:
			num[i] = str(k + 1)
			v = v + arr[j] - arr[k]
			break
	if v == 0:
		break
if len(num) == 0:
	print(-1)
else:
	print(''.join(num))


n = int(input())
l = list(map(int, input().split()))
max = 0
fin = []
hash = {}
count = 1
for i in range(1, 10):
	hash[i] = l[i - 1]
for i in l:
	lent = n // i
	left = n - lent * i
	yo = str(count) * lent
	if lent > max:
		max = lent
	count += 1
if max != 0:
	count = 1
	for i in l:
		lent = n // i
		left = n - lent * i
		yo = str(count) * lent
		if lent == max:
			fin.append([left, yo])
		count += 1
	fin.sort()
	hmm = fin[-1]
	ans = list(hmm[1])
	rep = ans[0]
	left = hmm[0]
	if rep != '9':
		for i in range(len(ans)):
			va = 1
			lub = left
			for j in l:
				if left + hash[int(rep)] - j >= 0:
					lub = left + hash[int(rep)] - j
					ans[i] = str(va)
				va += 1
			left = lub
	print(''.join(ans))
else:
	print(-1)


v = int(input())
a = list(map(int, input().split()))
(index, val) = (-1, 10 ** 12)
for i in range(len(a)):
	if a[i] <= val:
		val = a[i]
		index = i
m = v // val
ans = [str(index + 1) for x in range(m)]
if not len(set(a)) == 1:
	left = v - m * val
	for i in range(len(ans)):
		potential = left + val
		for (j, k) in enumerate(reversed(a)):
			if k <= potential:
				left = potential - k
				ans[i] = str(9 - j)
				break
print(''.join(ans) if ans else -1)


n = int(input())
w = list(map(int, input().split(' ')))
idx = 0
val = w[0]
for x in range(9):
	if val >= w[x]:
		val = w[x]
		idx = x
dig = n // val
ans = ''
m = n % val
if not dig:
	print(-1)
else:
	for x in range(8, idx - 1, -1):
		if w[x] == w[idx]:
			continue
		asdf = m // (w[x] - w[idx])
		ans += str(x + 1) * asdf
		m -= asdf * (w[x] - w[idx])
		dig -= asdf
print(ans + str(idx + 1) * dig)


import sys
from sys import stdin, stdout

def findbestwithin(re):
	global cost
	s = -1
	m1 = re
	for i in range(len(cost)):
		if cost[i] <= m1 and i > s:
			s = i
	return s

def findminnumber():
	global cost
	s = -1
	m1 = sys.maxsize
	co = cost
	for i in range(len(co)):
		if co[i] < m1 or (co[i] == m1 and i > s):
			s = i
			m1 = co[i]
	return s
m = int(input())
cost = list(map(int, input().split(' ')))
if min(cost) > m:
	print(-1)
else:
	d = {}
	t1 = findminnumber()
	t2 = m // cost[t1]
	t3 = m % cost[t1]
	d[t1 + 1] = t2
	if t3 == 0:
		for i in d:
			for j in range(d[i]):
				stdout.write(str(i))
	else:
		getbest = findbestwithin(cost[t1] + t3)
		while getbest != -1:
			if getbest > t1:
				t3 = t3 + cost[t1] - cost[getbest]
				if getbest + 1 in d:
					d[getbest + 1] += 1
				else:
					d[getbest + 1] = 1
				d[t1 + 1] -= 1
			if getbest == t1:
				break
			getbest = findbestwithin(cost[t1] + t3)
		t4 = list(d.keys())
		t4.sort()
		t4.reverse()
		for i in t4:
			for j in range(d[i]):
				stdout.write(str(i))


n = int(input())
a = list(map(int, input().split()))
ans = []
minimum = 10000000000.0
min_val = -1
for i in range(0, len(a)):
	if a[i] <= minimum:
		minimum = a[i]
		min_val = i + 1
ans = [min_val] * (n // minimum)
if min(a) > n:
	print(-1)
elif min_val == 9 or n % minimum == 0:
	print(''.join([str(x) for x in ans]))
else:
	n = n % minimum
	x = min([a[i] - minimum for i in range(len(a)) if i > min_val - 1])
	ind = 0
	while n >= x:
		for i in range(9, min_val, -1):
			if a[i - 1] - a[min_val - 1] <= n:
				ans[ind] = i
				n = n - (a[i - 1] - a[min_val - 1])
				ind += 1
				break
	print(''.join([str(x) for x in ans]))


v = int(input())
l = list(map(int, input().split()))
min1 = 100000000000
ind = 0
l1 = []
for i in range(9):
	if l[i] <= min1:
		min1 = l[i]
		ind = i
l1 = [str(ind + 1)] * (v // min1)
if l1 == []:
	print(-1)
else:
	rem = v % min1
	for i in range(len(l1)):
		k = 0
		for j in range(8, ind, -1):
			if rem + l[ind] >= l[j]:
				rem = rem + l[ind] - l[j]
				l1[i] = str(j + 1)
				k = 1
				break
		if k == 0:
			break
	for i in range(len(l1)):
		print(l1[i], end='')
	print()


import os
import sys
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
from math import inf

def main():
	w = int(input())
	a = list(map(int, input().split()))
	mm = min(a)
	n = w // mm
	if n == 0:
		print(-1)
		exit()
	if w % mm == 0:
		mi = 9
		for item in a[::-1]:
			if item == mm:
				break
			mi -= 1
		print(f'{mi}' * (w // mm))
		exit()
	else:
		for i in range(n, 0, -1):
			for j in range(8, -1, -1):
				if w - a[j] >= mm * (i - 1):
					print(j + 1, end='')
					w -= a[j]
					break
		print()

def nouse0():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse1():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse2():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def nouse3():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse4():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse5():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
main()


def lastIndex(array, element):
	i = len(array) - 1
	while i >= 0:
		if array[i] == element:
			return i
		i = i - 1
	return -1
v = int(input())
array = list(map(int, input().split()))
minimum = min(array)
if minimum > v:
	print(-1)
index = lastIndex(array, minimum)
string = [index + 1] * (v // minimum)
remainPaint = v % minimum
if remainPaint > 0:
	for i in range(len(string)):
		for j in range(len(array) - 1, index, -1):
			if remainPaint + minimum - array[j] >= 0:
				string[i] = j + 1
				remainPaint = remainPaint + minimum - array[j]
				break
		if remainPaint == 0:
			break
string = ''.join(map(str, string))
print(string)


v = int(input())
ai = list(map(int, input().split()))
x = ai.index(min(ai))
valofdi = ai[x]
length = v // ai[x]
if length == 0:
	print(-1)
	exit()
val = list(str(str(x + 1) * length))
v -= length * valofdi
for i in range(length):
	v += valofdi
	for ii in range(8, -1, -1):
		if ai[ii] <= v:
			val[i] = str(ii + 1)
			v -= ai[ii]
			break
	else:
		break
print(''.join(val))


n = int(input())
ai = [int(x) for x in input().split()]
mcDigit = 0
for i in range(9):
	if ai[i] <= ai[mcDigit]:
		mcDigit = i
di = [x - mcDigit for x in ai]
resLen = n // ai[mcDigit]
res = [mcDigit] * resLen
remain = n - resLen * ai[mcDigit]
for i in range(resLen):
	if remain <= 0:
		break
	d = 8
	while d > mcDigit:
		if remain >= ai[d] - ai[mcDigit]:
			res[i] = d
			remain -= ai[d] - ai[mcDigit]
			break
		d -= 1
	if d == mcDigit:
		break
out = ''
for i in res:
	out = out + str(i + 1)
if resLen == 0:
	print('-1')
else:
	print(out)