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
Tags: Dynamic programming

Data structures

Implementation

Greedy algorithms
Skill types: Dynamic programming

Data structures

Greedy algorithms

Starter code:

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)))


v = int(input())
a = [0] + list(map(int, input().split()))
b = [True for _ in range(10)]
for i in range(9, 0, -1):
	j = 1
	while j < i and b[i]:
		if a[j] >= a[i]:
			b[j] = False
		j += 1
num = []
c = []
for i in range(1, 10):
	if b[i]:
		num.append(i)
		c.append(a[i])
dp = [[0 for _ in range(len(num) + 2)] for _ in range(v + 1)]
dp[0][0] = 1
m = 0
a = []
for i in range(1, v + 1):
	for j in range(len(num)):
		if i < c[j]:
			continue
		if dp[i - c[j]][0] == 1:
			if dp[i][0] != 1:
				for k in range(len(num) + 2):
					dp[i][k] = dp[i - c[j]][k]
				dp[i][-1] += 1
				dp[i][j + 1] += 1
			elif dp[i - c[j]][-1] + 1 >= dp[i][-1]:
				for k in range(len(num) + 2):
					dp[i][k] = dp[i - c[j]][k]
				dp[i][-1] += 1
				dp[i][j + 1] += 1
	if dp[i][-1] >= m:
		m = dp[i][-1]
		a = dp[i]
if m == 0:
	print(-1)
else:
	s = ''
	for i in range(1, len(a) - 1):
		s += str(num[i - 1]) * a[i]
	print(s[::-1])


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)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.setrecursionlimit(int(pow(10, 6)))
	sys.stdin = open('input.txt', 'r')
except:
	pass
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))
endtime = time.time()


import sys, math
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

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

def listStr():
	return list(input().strip())
import collections as col
import math

def solve():
	V = getInt()
	A = getInts()
	nums_dict = {}
	for j in range(9):
		nums_dict[j + 1] = A[j]
	min_A = min(A)
	for j in range(9, 0, -1):
		if nums_dict[j] == min_A:
			best_index_min = j
			break
	max_digs = V // min_A
	if max_digs == 0:
		print(-1)
		return
	curr_ans = [best_index_min] * max_digs
	R = V - max_digs * min_A
	curr_dig = 0
	while R:
		for j in range(9, best_index_min, -1):
			flag = False
			if R >= nums_dict[j] - min_A:
				curr_ans[curr_dig] = j
				flag = True
				R -= nums_dict[j] - min_A
				break
		if curr_dig == max_digs or not flag:
			print(*curr_ans, sep='')
			return
		curr_dig += 1
	print(*curr_ans, sep='')
	return
solve()


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)


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


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))


n = int(input())
S = list(map(int, input().split()))
K = [0] * 9
m = min(S)
d = 0
di = 0
len = n // m
if not len:
	print(-1)
else:
	for i in range(8, -1, -1):
		if S[i] == m:
			d = i + 1
			break
	n -= n // m * m
	S = list(map(lambda x: x - m, S))
	for i in range(8, -1, -1):
		if S[i]:
			print(str(i + 1) * (n // S[i]), end='')
			len -= n // S[i]
			n -= n // S[i] * S[i]
		else:
			print(str(i + 1) * len)
			n = 0
			break


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())
vals = list(map(int, input().strip().split()))
mini = min(vals)
minI = -1
for i in range(9):
	if vals[i] == mini:
		miniI = i
tot = v // min(vals)
num = [str(miniI + 1) for i in range(tot)]
remain = v - vals[miniI] * tot
if len(num) == 0:
	print(-1)
else:
	if remain > 0:
		for i in range(tot):
			for j in range(8, miniI, -1):
				if vals[miniI] + remain >= vals[j]:
					num[i] = str(j + 1)
					remain = vals[miniI] + remain - vals[j]
					break
	print(''.join((i for i in num)))


import sys
TESTING = False

def solve():
	(start,) = read()
	costs = read()
	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:
		return -1
	else:
		ans = ''.join(map(str, best))
		return ans

def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return list(map(int, inputs.split()))

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')

def run():
	if TESTING:
		sys.stdin = open('test.txt')
	res = solve()
	write(res)
run()


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())
A = list(map(int, input().split()))
if v < min(A):
	print(-1)
else:
	basic = 1
	for i in range(9):
		if A[i] <= A[basic - 1]:
			basic = i + 1
	ans = [basic] * (v // A[basic - 1])
	ost = v % A[basic - 1]
	now = 0
	find = True
	while find:
		find = False
		for i in range(8, basic - 1, -1):
			if A[i] <= A[basic - 1] + ost:
				ans[now] = i + 1
				ost = ost + A[basic - 1] - A[i]
				now += 1
				find = True
				break
	print(''.join(list(map(str, 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())
a = [int(x) for x in input().split()]
mini = float('inf')
for i in range(9):
	if a[i] <= mini:
		mini = a[i]
		ind = i
if v < mini:
	print(-1)
else:
	lena = v // mini
	ans = [ind + 1] * lena
	rem = v % mini
	x = 0
	i = 9
	while i > ind + 1:
		if a[i - 1] <= rem + mini:
			ans[x] = str(i)
			rem = rem + mini - a[i - 1]
			x += 1
			if x == lena:
				break
		else:
			i -= 1
	for i in ans:
		print(i, end='')


v = int(input())
a = [int(i) for i in input().split()]
mini = min(a)
count = v // mini
res = v % mini
nr = ''
ok = True
while v and count and ok:
	min = max(a)
	val = -1
	for j in range(9, -1, -1):
		i = j - 1
		if (count - 1) * mini + a[i] <= v:
			v -= a[i]
			res -= a[i] - mini
			count -= 1
			nr += str(j)
			break
	else:
		break
	if res == 0:
		break
if count:
	for j in range(9, -1, -1):
		i = j - 1
		if a[i] == mini:
			nr += str(j) * count
			break
if nr == '':
	print(-1)
else:
	print(nr)


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()


n = int(input())
l = list(map(int, input().split()))
min_cost = 10 ** 6 + 1
nu = 0
for i in range(1, 10):
	if l[i - 1] <= min_cost:
		nu = i
		min_cost = l[i - 1]
if n < min_cost:
	print(-1)
	exit()
x = n // min_cost
left = n - x * min_cost
ans = [str(nu)] * x
for j in range(x):
	to_s = -1
	for i in range(9):
		if l[i] <= left + l[nu - 1] and i > nu - 1:
			to_s = i + 1
	if to_s == -1:
		break
	ans[j] = str(to_s)
	left = left + l[nu - 1] - l[to_s - 1]
print(''.join(ans))


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())
arr = list(map(int, input().split()))
mn = int(10000000.0)
index = 0
for i in range(len(arr)):
	if mn >= arr[i]:
		mn = arr[i]
		index = i
if mn > n:
	print(-1)
else:
	ans = []
	for i in range(n // mn):
		ans.append(index + 1)
	avl = n % mn
	for i in range(len(ans)):
		for j in range(len(arr) - 1, -1, -1):
			if arr[j] <= avl + arr[ans[i] - 1]:
				avl = avl - (arr[j] - arr[ans[i] - 1])
				ans[i] = j + 1
				break
	for x in ans:
		print(x, end='')


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)


import sys
import bisect
import heapq
from time import perf_counter
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter as c
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
n = int(data())
arr = l()
ele = min(arr)
index = -1
for i in range(8, -1, -1):
	if arr[i] == ele:
		index = i + 1
		break
answer = [str(index) for i in range(n // ele)]
if len(answer) == 0:
	out('-1')
	exit(0)
diff = n - len(answer) * ele
possible = []
j = 0
while diff > 0 and perf_counter() < 0.5:
	result = '0'
	for i in range(9):
		if diff + ele >= arr[i]:
			temp = str(i + 1) * ((diff + ele) // arr[i])
			if int(temp) >= int(result):
				result = temp
				k = arr[i]
	for i in range(len(result)):
		if answer[j] < result[i]:
			diff = diff + ele - k
			answer[j] = result[i]
			if j < len(answer) - 1:
				j += 1
print(''.join(answer))


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)))


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
n = iinp()
arr = lmp()
mn = min(arr)
d = n // mn
if d == 0:
	print(-1)
else:
	rem = n % mn
	for i in range(d):
		rem += mn
		for j in range(8, -1, -1):
			if arr[j] <= rem:
				break
		print(j + 1, end='')
		rem -= arr[j]


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)


a = int(input())
A = list(map(int, input().split()))
min = min(A)
len = a // min
if len == 0:
	print(-1)
	exit()
rem = a % min
word = ''
S = [str(i) for i in range(1, 10)]
for i in range(len):
	j = A.__len__()
	while j > 0:
		if A[j - 1] - min <= rem:
			rem -= A[j - 1] - min
			break
		j -= 1
	word += S[j - 1]
print(word)


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)))


totalVol = int(input())
Vol = [int(var) for var in input().split()]
ans = []
(minConsumption, maxConsumption) = (min(Vol), max(Vol))
maxDigits = totalVol // minConsumption
potentialNum = -1
if maxDigits != 0 and minConsumption != maxConsumption:
	(currDigit, potentialNum) = (0, 0)
	while totalVol != 0:
		currDigit += 1
		confirmedNum = 0
		for i in reversed(range(9)):
			if currDigit + max(totalVol - Vol[i], 0) // minConsumption >= maxDigits and totalVol >= Vol[i]:
				confirmedNum = i + 1
				break
		if confirmedNum == 0:
			break
		totalVol -= Vol[confirmedNum - 1]
		ans.append(str(confirmedNum))
if minConsumption == maxConsumption and maxDigits != 0:
	print('9' * maxDigits)
elif len(ans) != 0:
	print(''.join(ans))
else:
	print(-1)


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)))


from sys import stdin, stdout, stderr
v = int(input())
a = [int(x) for x in stdin.readline().split()]
if v < min(a):
	stdout.write('-1')
	exit()
maxlen = v // min(a)
for i in range(8, -1, -1):
	while a[i] <= v:
		if 1 + (v - a[i]) // min(a[:i + 1]) == maxlen:
			print(i + 1, sep='', end='')
			maxlen -= 1
			v = v - a[i]
		else:
			break


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))


from math import *
v = int(input())
arr = [0] + list(map(int, input().split()))
sz = inf
num = 1
for i in range(1, 10):
	if arr[i] <= sz:
		sz = arr[i]
		num = i
ln = v // sz
rem = v % sz
ans = ''
f = 1
while f:
	f = 0
	for i in range(9, num, -1):
		if sz + rem >= arr[i]:
			ans += str(i)
			rem -= arr[i] - sz
			f = 1
			ln -= 1
			break
ans += str(num) * ln
if ans == '':
	print(-1)
else:
	print(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)


t = int(input())
d = {}
l = list(map(int, input().split()))
for i in range(9):
	j = l[i]
	d[j] = i + 1
e = list(d.keys())
x = min(e)
g = t // x
f = t % x
if g == 0:
	print(-1)
else:
	a = []
	b = []
	for i in range(g):
		a.append(x)
	while len(a) != 0:
		j = a.pop()
		f = f + j
		m = 0
		l = f
		for j in e:
			if f - j >= 0 and m < d[j]:
				m = d[j]
				l = f - j
		f = l
		b.append(m)
	print(*b, sep='')


v = int(input())
arr = list(map(int, input().split()))
min1 = min(arr)
if v == 0:
	print('-1')
elif min1 > v:
	print(-1)
else:
	rem = v // min1
	for i in range(rem, 0, -1):
		for j in range(9, 0, -1):
			if v - arr[j - 1] >= min1 * (i - 1):
				print(j, end='')
				v -= arr[j - 1]
				break
	print()


a = int(input())
z = list(map(int, input().split()))
from collections import defaultdict
al = defaultdict(int)
for i in range(len(z)):
	al[z[i]] = max(i + 1, al[z[i]])
maxa = 0
save = 0
coin = 0
for i in range(len(z)):
	if a // z[i] > maxa:
		maxa = a // z[i]
		coin = i + 1
	if maxa == a // z[i]:
		if z[coin - 1] > z[i]:
			coin = i + 1
cot = a - maxa * z[coin - 1]
cost = z[coin - 1]
ans = []
for i in range(maxa):
	ans.append(coin)
for i in range(len(ans)):
	for j in range(8, -1, -1):
		if cot + cost - z[j] >= 0:
			cot = cot + cost - z[j]
			ans[i] = j + 1
			break
if len(ans) == 0:
	print(-1)
else:
	print(''.join(map(str, ans)))


from sys import stdin, stdout
stdin.readline

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

def it():
	return int(stdin.readline().strip())
from collections import defaultdict as dd, Counter as C, deque
from math import ceil, gcd, sqrt, factorial, log2, floor
import heapq

def get_key(val, my_dict):
	for (key, value) in my_dict.items():
		if val == value:
			return key
n = it()
l = mp()
s = set()
d = dd(lambda : 0)
if n < min(l):
	print(-1)
	exit()
for i in range(9):
	if l[i] in d.values():
		del d[get_key(l[i], d)]
		d[i + 1] = l[i]
	else:
		d[i + 1] = l[i]
mi = min(d.values())
key = get_key(mi, d)
s = str(key) * (n // mi)
n = n % mi
if n == 0:
	print(s)
elif key == 9:
	print(s)
else:
	x = list(d.keys())
	for i in x:
		if i < key:
			del d[i]
	l = sorted(d.keys(), reverse=True)
	(i, j) = (0, 0)
	s = list(s)
	tt = len(s)
	while n and i < tt and (j < len(l)):
		if int(s[i]) < l[j]:
			if n + d[int(s[i])] >= d[l[j]]:
				n -= d[l[j]] - d[int(s[i])]
				s[i] = str(l[j])
				i += 1
			else:
				j += 1
		else:
			j += 1
	print(''.join(s))


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, input().split()))
for i in range(1):
	n = nmbr()
	a = lst()
	f = 1
	dp = [0] * (1 + n)
	fd = [0] * (1 + n)
	l = []
	for i in range(1, n + 1):
		x = -1
		used = 0
		for digit in range(9, 0, -1):
			if i >= a[digit - 1] and dp[i - a[digit - 1]] > x:
				x = dp[i - a[digit - 1]]
				used = digit
		dp[i] = x + 1
		fd[i] = used
	col = n
	while col > 0:
		if fd[col] == 0:
			f = 0
			break
		l += [fd[col]]
		col -= a[fd[col] - 1]
	if l:
		for v in l:
			stdout.write(str(v))
	else:
		print(-1)


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))


v = int(input())
a = [1000000000000] + list(map(int, input().split()))
d = 0
for i in range(9, 0, -1):
	if a[i] == min(a):
		d = i
		break
l = v // a[d]
rest = v - l * a[d]
essa = []
while rest:
	for i in range(9, d, -1):
		if a[i] - a[d] <= rest:
			rest -= a[i] - a[d]
			essa.append(str(i))
			break
	else:
		break
res = ''.join(essa) + ''.join([str(d)] * (l - len(essa)))
print(res if res else -1)


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def solution():
	n = int(input())
	l = list(map(int, input().split()))
	x = 0
	num = 0
	mx = 2000000000.0
	for i in range(9):
		if mx >= l[i]:
			mx = l[i]
			num = i + 1
	x = n // mx
	if x == 0:
		print(-1)
		return
	y = n - mx * x
	while x > 0:
		if y == 0:
			print(num, end='')
		else:
			ll = num
			for i in range(ll, 9):
				if l[i] - l[num - 1] <= y:
					ll = i + 1
			print(ll, end='')
			y -= l[ll - 1] - l[num - 1]
		x -= 1
t = 1
for _ in range(t):
	solution()


x = int(input())
l = [0] + list(map(int, input().split(' ')))
m = 10 ** 9
ind = 0
for i in range(1, 10):
	if l[i] <= m:
		m = l[i]
		ind = i
if m > x:
	print(-1)
	quit()
dig = x // m
k = [ind] * dig
left = x - dig * m
for i in range(dig):
	for j in range(9, 0, -1):
		diff = l[j] - l[k[i]]
		if diff <= left:
			left -= diff
			k[i] = str(j)
			break
	k[i] = str(k[i])
print(''.join(k))


v = int(input())
costos = [int(x) for x in input().split()]
maximos = []
maximo = -1
for (num, k) in enumerate(costos[::-1]):
	if v // k > maximo:
		maximos = [9 - num]
		maximo = v // k
	elif v // k == maximo:
		maximos.append(9 - num)
if maximo == 0:
	print(-1)
elif maximos[0] == 9:
	print(str(9) * maximo)
else:
	new_m = []
	for k in maximos:
		st = str(k) * maximo
		p = v % costos[k - 1]
		act = 9
		mov = 0
		while p > 0 and act > k:
			try:
				rt = int(p // (costos[act - 1] - costos[k - 1]))
			except:
				rt = 0
			st = st[:mov] + str(act) * rt + st[mov:]
			p = p - rt * (costos[act - 1] - costos[k - 1])
			mov += rt
			st = st[:maximo]
			act -= 1
		new_m.append(st)
	print(max(new_m))


import sys
v = int(input().strip())
a_original = [int(x) for x in input().strip().split()]
a = [(i + 1, a_original[i]) for i in range(len(a_original))]
a.sort(key=lambda x: (x[1], -x[0]))
digits = [a[0][0] for _ in range(v // a[0][1])]
remaining = v % a[0][1]
a2 = [x for x in a[1:] if x[0] > a[0][0]]
a2.sort(key=lambda x: -x[0])
if remaining != 0:
	idx = 0
	while idx < len(digits):
		candidate = 0
		for (d, w) in a2:
			if remaining + a[0][1] - w >= 0:
				candidate = d
				break
		else:
			break
		digits[idx] = candidate
		remaining = remaining + a[0][1] - a_original[d - 1]
		idx += 1
if len(digits) == 0:
	print(-1)
else:
	print(''.join((str(d) for d in digits)))


import sys
inf = float('inf')

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

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

def input():
	return sys.stdin.readline().strip()
n = int(input())
Arr = get_array()
mini = min(Arr)
maxi = n // mini
flag = 0
for i in range(1, maxi + 1):
	for j in range(9, -1, -1):
		rem = n - Arr[j - 1]
		if rem < 0:
			continue
		if rem // mini >= maxi - i:
			print(j, end='')
			flag = 1
			n = rem
			break
if flag == 0:
	print(-1)


def main():
	v = int(input())
	w = list(map(int, input().rstrip().split()))
	cost = dict(zip(range(1, 10), w))
	tsoc = dict(zip(w, range(1, 10)))
	minCost = min(tsoc.keys())
	if minCost > v:
		print(-1)
		return
	l = int(v / minCost)
	ans = [tsoc[minCost]] * l
	v -= l * minCost
	for i in range(len(ans)):
		for n in reversed(range(ans[i] + 1, 10)):
			d = cost[n] - cost[ans[i]]
			if v >= d:
				ans[i] = n
				v -= d
				break
	print(''.join(map(str, ans)))
	return
main()


v = int(input())
a = list(map(int, input().split()))
if v >= min(a):
	n = max([i for (i, j) in enumerate(a) if j == min(a)]) + 1
	res = [str(n)] * (v // min(a))
	cost = v // min(a) * min(a)
	for i in range(len(res)):
		for j in range(8, int(res[i]) - 1, -1):
			if cost - a[int(res[i]) - 1] + a[j] <= v:
				cost += a[j] - a[int(res[i]) - 1]
				res[i] = str(j + 1)
				break
	print(''.join(res))
else:
	print(-1)


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


import os, sys, math
from io import BytesIO, IOBase
from collections import defaultdict, deque, OrderedDict
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(input())

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

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

def Sn():
	return input().strip()
BUFSIZE = 8192

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def solve():
	v = I()
	l = list(In())
	d = {}
	if v == 0:
		print(-1)
		return
	mn = float('inf')
	for i in range(9):
		d[i + 1] = l[i]
		mn = min(mn, l[i])
	chance = []
	for i in range(1, 10):
		if d[i] == mn:
			chance.append(i)
	mx_len = 0
	ans = [0] * 10
	for x in chance:
		if v // d[x] >= mx_len:
			mx_len = v // d[x]
			rem = v % d[x]
			temp = [0] * 10
			temp[x] = mx_len
			ok = True
			while ok and rem:
				ok = False
				for i in range(9, x, -1):
					if i == x:
						continue
					if rem + d[x] >= d[i]:
						temp[i] += 1
						rem -= d[i] - d[x]
						temp[x] -= 1
						ok = True
						break
			ch = False
			for i in range(9, 0, -1):
				if temp[i] > ans[i]:
					ch = True
					break
			ans = temp.copy()
	if sum(ans) == 0:
		print(-1)
		return
	for i in range(9, 0, -1):
		for j in range(ans[i]):
			print(i, end='')
	print()
	pass

def main():
	T = 1
	for i in range(T):
		solve()
M = 998244353
P = 1000000007

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')
main()


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)


v = int(input())
a = list(map(int, input().split()))
m = min(a)
if v < m:
	print(-1)
else:
	a = [0] + a
	d = [0] * 10
	k = 9 - a[::-1].index(m)
	n = v // m
	d[k] = n
	v -= n * m
	for i in range(0, n):
		for j in range(9, k, -1):
			if v >= a[j] - a[k]:
				v -= a[j] - m
				d[j] += 1
				d[k] -= 1
				break
		if v <= 0:
			break
	for i in range(9, k - 1, -1):
		print(str(i) * d[i], end='')
	print()


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))


__author__ = 'runekri3'
v = int(input())
digit_costs = [10 ** 7] + list(map(int, input().split()))
temp_list = list(enumerate(digit_costs[:]))
temp_list.sort(key=lambda item: item[1], reverse=True)
temp_list.reverse()
digits_by_price = [digit for (digit, cost) in temp_list]
cheapest_digit = digits_by_price[0]
extra_costs = [digit_cost - digit_costs[cheapest_digit] for digit_cost in digit_costs]
better_digits = [i for i in range(1, 10) if i > cheapest_digit]
better_digits.sort(reverse=True)
max_len = int(v / digit_costs[cheapest_digit])
if max_len > 0:
	current_number = [str(cheapest_digit)] * max_len
	leftover = v % digit_costs[cheapest_digit]
	for index_being_changed in range(max_len):
		for better_digit in better_digits:
			if extra_costs[better_digit] <= leftover:
				leftover -= extra_costs[better_digit]
				current_number[index_being_changed] = str(better_digit)
				break
		else:
			break
else:
	current_number = '-1'
print(''.join(current_number))


n = int(input())
a = [int(i) for i in input().split()]
mx = 0
good = -1
t = min(a)
if n < t:
	print(-1)
else:
	for i in range(len(a)):
		k = n // a[i]
		if k >= mx:
			good = i + 1
			mx = k
	now = n
	index = len(a) - 1
	for i in range(mx):
		if (now - a[index]) // t >= mx - i - 1:
			print(index + 1, end='')
			now -= a[index]
		else:
			while index > -1 and (now - a[index]) // t < mx - i - 1:
				index -= 1
			print(index + 1, end='')
			now -= a[index]


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())
a = list(map(int, input().split()))
mincost = min(a)
dig = v // mincost
if dig == 0:
	print(-1)
	exit()
for i in range(dig, 0, -1):
	for j in range(9, 0, -1):
		if v - a[j - 1] >= mincost * (i - 1):
			print(j, end='')
			v -= a[j - 1]
			break
print()


def main():
	from functools import cmp_to_key

	def cmp(i, j):
		nonlocal a
		if a[i] == a[j]:
			return j - i
		return a[i] - a[j]
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = sorted(list(range(9)), key=cmp_to_key(cmp))
	d = n // a[b[0]]
	s = list(str(b[0] + 1) * d)
	p = n - d * a[b[0]]
	for i in range(d):
		x = a[ord(s[i]) - 1 - ord('0')]
		for j in range(8, -1, -1):
			if x + p >= a[j]:
				p -= a[j] - a[ord(s[i]) - 1 - ord('0')]
				s[i] = chr(j + ord('1'))
				break
	if len(s) == 0:
		return '-1'
	return ''.join(s)
print(main())


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()


n = int(input())
a = list(map(abs, map(int, input().split())))
if min(a) > n:
	print(-1)
else:
	m = min(a)
	j = 8
	while a[j] != m:
		j -= 1
	c = n // m
	ans = [str(j + 1)] * c
	n -= c * a[j]
	i = 8
	z = 0
	while i > j and n != 0:
		if a[j] + n >= a[i]:
			while z < len(ans) and a[j] + n >= a[i]:
				n += a[j]
				n -= a[i]
				ans[z] = str(i + 1)
				z += 1
		i -= 1
	print(''.join(ans))


v = int(input())
a = [*map(int, input().split())]
d = {}
for i in range(9):
	d[a[i]] = i + 1
ans = [*str(d[min(a)]) * (v // min(a))]
t = min(a) * len(ans)
for i in range(len(ans)):
	t -= a[int(ans[i]) - 1]
	for j in range(8, -1, -1):
		if t + a[j] <= v:
			ans[i] = str(j + 1)
			t += a[j]
			break
print(''.join(ans) if len(ans) else -1)


import sys
n = int(sys.stdin.readline())
l = list(map(int, sys.stdin.readline().split()))
if n < min(l):
	print(-1)
else:
	a = [0] * 9
	for i in range(9):
		a[i] = n // l[i]
	le = -1
	k = -1
	for i in range(9):
		if a[i] > le:
			le = a[i]
			k = i
	digit = k + 1
	m = l[k]
	ans = list(le * str(k + 1))
	rem = n - m * le
	arr = [0] * 9
	for i in range(9):
		arr[i] = l[i] - m
	i = 8
	j = 0
	while i >= k + 1 and j < 9 and (rem > 0):
		if arr[i] == 0:
			i -= 1
			continue
		add = rem // arr[i]
		if add == 0:
			i -= 1
			continue
		for mm in range(add):
			ans[j] = i + 1
			j += 1
		rem %= arr[i]
	i = 0
	j = 0
	while j < len(ans):
		i = int(ans[j])
		while i < 9:
			if l[int(ans[j]) - 1] == l[i]:
				ans[j] = str(i + 1)
			i += 1
		j += 1
	for i in range(len(ans)):
		ans[i] = str(ans[i])
	print(''.join(ans))


import sys
import math
from collections import defaultdict

def read_line():
	return sys.stdin.readline()[:-1]

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

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def fun(a, v):
	for (i, k) in enumerate(a[::-1]):
		if v >= k:
			return (k, 8 - i)
	return -1
v = read_int()
a = read_int_line()
c = 1000000000.0
val = -1
for i in range(8, -1, -1):
	if a[i] < c:
		c = a[i]
		val = i
val += 1
ans = -1
if c < v:
	ans = v // c
	v -= ans * a[val - 1]
	ans = ans * str(val)
	j = 0
	while v >= 0 and j < len(ans):
		u = int(ans[j])
		k = fun(a, v + a[val - 1])
		if u > k[1]:
			break
		t = k[0]
		if t != -1:
			v = v + a[val - 1] - t
			ans = ans[:j] + str(k[1] + 1) + ans[j + 1:]
		j += 1
	print(ans)
else:
	ans = -1
	print(ans)


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()


import sys
import math as mt
import bisect
t = 1

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve():
	d = {}
	j = 1
	for i in range(9):
		d[l[i]] = i + 1
	mini = min(l[:])
	x = n // mini
	rem = n % mini
	ans = [d[mini]] * x
	for i in range(len(ans)):
		(x, rem1) = (d[mini], rem)
		for j in range(d[mini], 9):
			if l[j] <= rem + mini:
				x = j + 1
				rem1 = rem + mini - l[j]
		ans[i] = x
		rem = rem1
	if x == 0:
		return [-1]
	else:
		return ans
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(*solve(), sep='')


import sys
sys.setrecursionlimit(100000)

def solve(v, a):
	min_value = min(a)

	def rec(v):
		if v == 0 or v < min_value:
			return ''
		a.sort(key=lambda x: ((v - x[1]) // min_value, x[0]), reverse=True)
		(number, price) = a[0]
		if price == min_value:
			return str(number) * (v // price) + rec(v % price)
		optimal_digits = (v - price) // min_value + 1
		i = (v - min_value * optimal_digits) // (price - min_value)
		return str(number) * i + rec(v - i * price)
	a = list(enumerate([10 ** 7] + a))
	return rec(v)
v = int(input())
a = list(map(int, input().split()))
r = solve(v, a)
if not r or r == '':
	print(-1)
else:
	print(r)


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)


total_paint = int(input())
paints_used = list(map(int, input().split()))
min_v = min(paints_used)
if min_v > total_paint:
	print(-1)
	exit(0)
min_at = 9 - paints_used[::-1].index(min_v)
max_length = total_paint // min_v
ans = [min_at] * max_length
ans_sum = min_v * max_length
for i in range(max_length):
	for (j, v) in enumerate(paints_used[::-1]):
		if ans_sum - min_v + v <= total_paint:
			ans[i] = 9 - j
			ans_sum = ans_sum - min_v + v
			break
for i in ans:
	print(i, end='')
print('')


v = int(input())
s = input().split()
ar = []
for x in range(1, 10):
	ar.append(int(s[x - 1]))
minn = min(ar)
ln = v // minn
num = ln
if num == 0:
	print(-1)
else:
	tmp = v
	while num:
		for i in range(8, -1, -1):
			if ar[i] <= tmp and (tmp - ar[i]) // minn == num - 1:
				print(i + 1, end='')
				tmp -= ar[i]
				num -= 1
				break


v = int(input())
a = list(map(int, input().split()))
c = [0 for i in range(10)]
globMin = float('inf')
globMinIndex = -1
for i in range(9):
	if a[i] <= globMin:
		globMin = a[i]
		globMinIndex = i
c[globMinIndex + 1] = v // globMin
ans = v // globMin
v = v % globMin
for i in range(9, globMinIndex + 1, -1):
	if v <= 0:
		break
	j = i - 1
	c[i] += v // (a[i - 1] - globMin)
	c[globMinIndex + 1] -= v // (a[i - 1] - globMin)
	v = v % (a[i - 1] - globMin)
r = ''
for i in range(9, 0, -1):
	r += str(i) * c[i]
if ans == 0:
	print(-1)
else:
	print(r)


v = int(input())
a = [10 ** 6] + list(map(int, input().split()))
if v < min(a):
	print(-1)
	exit()
am = 10 ** 6
dm = 0
for i in range(1, 10):
	if a[i] <= am:
		am = a[i]
		dm = i
(q, r) = divmod(v, am)
ans = [dm] * q
for i in range(q):
	for j in range(9, dm, -1):
		if r + am >= a[j]:
			ans[i] = j
			r -= a[j] - am
			break
	else:
		break
print(''.join(map(str, ans)))


class HalfDead:

	def __init__(self):
		self.n = int(input())
		self.a = list(map(int, input().split()))

	def Game_On_Your_Lips(self):
		mx = 0
		good = -1
		t = min(self.a)
		if self.n < t:
			print(-1)
			exit()
		else:
			for i in range(len(self.a)):
				k = self.n // self.a[i]
				if k >= mx:
					good = i + 1
					mx = k
			now = self.n
			index = len(self.a) - 1
			for i in range(mx):
				if (now - self.a[index]) // t >= mx - i - 1:
					print(index + 1, end='')
					now -= self.a[index]
				else:
					while index > -1 and (now - self.a[index]) // t < mx - i - 1:
						index -= 1
					print(index + 1, end='')
					now -= self.a[index]
obj = HalfDead()
obj.Game_On_Your_Lips()


v = int(input())
a = list(map(int, input().split()))
a = a[::-1]
m = min(a)
x = 9 - a.index(m)
d = v // m
r = v % m
if d < 1:
	print(-1)
	exit()
c = d * [x]
i = 0
while i < d:
	t = m + r
	j = 0
	while a[j] > t:
		j += 1
	c[i] = 9 - j
	i += 1
	r = t - a[j]
print(''.join(map(str, c)))


v = int(input())
a = list(map(int, input().split()))
(m, j) = (a[0], 0)
for (i, x) in enumerate(a, 1):
	if x <= m:
		(m, j) = (x, i)
x = int(v / m)
if x == 0:
	print(-1)
else:
	while x:
		x -= 1
		i = 9
		while i:
			i -= 1
			if (v >= a[i]) & (int((v - a[i]) / m) == x):
				v -= a[i]
				print(i + 1, end='')
				break
		if i + 1 == j:
			break
	print(x * str(j))


import math
paint = int(input())
cost = list(map(int, input().split()))
cost_min = min(cost)
bruh = len(cost) - 1
while bruh >= 0:
	if cost[bruh] == cost_min:
		index_min = bruh
		break
	bruh -= 1
temp = str(index_min + 1) * math.floor(paint / cost_min)
balance = paint - cost_min * math.floor(paint / cost_min)
k = 0
z = -1
replace = ''
if len(temp) > 0:
	while True:
		f = 1
		if cost[z] <= balance + cost_min and cost[z] != cost_min:
			replace += str(z + len(cost) + 1)
			k += 1
			balance -= cost[z]
			balance += cost_min
			z = -1
			f = 0
		if cost[z] == cost_min:
			break
		if f == 1:
			z -= 1
	print(replace + temp[k:])
else:
	print(-1)


v = int(input())
l = list(map(int, input().strip().split()))
min1 = 10000000000
mini = 0
r = ''
for i in range(9):
	if l[i] <= min1:
		min1 = l[i]
		mini = i
digit = v // min1
left = v % min1
if digit == 0:
	print(-1)
	exit()
while digit > 0 and left > 0:
	f = 0
	for i in range(8, mini, -1):
		if left + min1 - l[i] >= 0:
			left = left + min1 - l[i]
			f = 1
			r = r + str(i + 1)
			break
	if f == 0:
		break
	digit = digit - 1
r = r + digit * str(mini + 1)
print(r)


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))


v = int(input())
a = list(map(int, input().split()))
d = 8
p = a[8]
for i in range(8, -1, -1):
	if a[i] < p:
		d = i
		p = a[i]
l = v // a[d]
d = d + 1
if v < p:
	print('-1')
else:
	v = v % p
	ans = [str(d)] * l
	i = 0
	j = 8
	while 1:
		if a[j] <= v + p:
			ans[i] = str(j + 1)
			i = i + 1
			v = v + p - a[j]
			if i == l or j == d - 2:
				break
		else:
			j = j - 1
			if j == d - 2:
				break
	print(''.join(ans))


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


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


from math import ceil, log2
from collections import deque
from sys import stdin
input = stdin.readline

def read():
	return [int(i) for i in input().split()]
n = int(input())
l = list(read())
m = min(l)
if n < m:
	print(-1)
	exit()
q = 0
for i in range(9):
	if m == l[i]:
		q = i + 1
s = n // l[q - 1]
ans = [q] * s
r = n % l[q - 1]
l = [i - m for i in l]
for i in range(s):
	for (j, v) in enumerate(reversed(l)):
		if v <= r:
			ans[i] = 9 - j
			r -= v
			break
print(''.join(map(str, ans)))


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)