N, M = map(int, input().split())
A = list(map(int, input().split()))

dp = [0] * N + [-1] * 9
for i in range(1, N+1):
    dp[i] = max(dp[i-int('0255456376'[a])] * 10 + a for a in A)

print(dp[N]) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split dp = [0] * N + [-1] * 9 dp [0] * N + [-1] * 9 [0] * N [0] 0 N [-1] * 9 [-1] -1 9 for i in range(1, N+1):
    dp[i] = max(dp[i-int('0255456376'[a])] * 10 + a for a in A) i range(1, N+1) range 1 N+1 N 1 dp[i] = max(dp[i-int('0255456376'[a])] * 10 + a for a in A) dp[i] dp i max(dp[i-int('0255456376'[a])] * 10 + a for a in A) max dp[i-int('0255456376'[a])] * 10 + a dp[i-int('0255456376'[a])] * 10 dp[i-int('0255456376'[a])] dp i-int('0255456376'[a]) i int('0255456376'[a]) int '0255456376'[a] '0255456376' a 10 a print(dp[N]) print dp[N] dp N N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M A = list(map(int, input().split())) list(map(int, input().split())) A dp = [0] * N + [-1] * 9 [0] * N + [-1] * 9 dp
N, M = map(int, input().split())
A = list(map(int, input().split()))

dp = [0] * N + [-1] * 9
for i in range(1, N+1):
    dp[i] = max(dp[i-int('0255456376'[a])] * 10 + a for a in A)

print(dp[N])