Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
for i in range(1, N+1):
    t = 0
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t

K = N
k = dp[N]
ans = ""
while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            if k == 1 and K != xa:
                continue
            ans += str(a)
            K -= xa
            k -= 1
            break
print(ans)

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
INF = float('inf')
for i in range(1, N+1):
    t = -INF
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t

K = N
k = dp[N]
ans = ""
while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
for i in range(1, N+1):
    t = 0
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t
K = N
ans = ""
while dp[K] > 0:
    for a in A:
        xa = x[a]
        if K >= xa and dp[K] == dp[K-xa] + 1:
            if dp[K] == 1 and K != xa:
                continue
            ans += str(a)
            K -= xa
            break
print(ans)

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
INF = float('inf')
for i in range(1, N+1):
    t = -INF
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t

K = N
k = dp[N]
ans = ""
while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
for i in range(2, N+1):
    t = 0
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t
K = N
ans = ""
while K > 0:
    for a in A:
        xa = x[a]
        if K >= xa and dp[K] == dp[K-xa] + 1:
            if dp[K] == 1 and K != xa:
                continue
            ans += str(a)
            K -= xa
            break
print(ans)

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
INF = float('inf')
for i in range(1, N+1):
    t = -INF
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t

K = N
k = dp[N]
ans = ""
while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
for i in range(2, N+1):
    t = 0
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t
K = N
ans = ""
while K > 0:
    for a in A:
        if K >= x[a] and dp[K] == dp[K-x[a]] + 1:
            if dp[K] == 1 and K != x[a]:
                continue
            ans += str(a)
            K -= x[a]
            break
print(ans)

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
INF = float('inf')
for i in range(1, N+1):
    t = -INF
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t

K = N
k = dp[N]
ans = ""
while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
for i in range(2, N+1):
    for a in A:
        if i >= x[a] and dp[i-x[a]] + 1 > dp[i]:
            dp[i] = dp[i-x[a]] + 1
K = N
ans = ''
while K > 0:
    for a in A:
        if K >= x[a] and dp[K] == dp[K-x[a]] + 1:
            if dp[K] == 1 and K != x[a]:
                continue
            ans += str(a)
            K -= x[a]
            break
print(ans)


Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
INF = float('inf')
for i in range(1, N+1):
    t = -INF
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t

K = N
k = dp[N]
ans = ""
while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
for i in range(2, N+1):
    for a in A:
        if i >= x[a] and dp[i-x[a]] + 1 > dp[i]:
            dp[i] = dp[i-x[a]] + 1
K = N
ans = ''
while K > 0:
    for a in A:
        if K >= x[a] and dp[K] == dp[K-x[a]] + 1:
            if dp[K] == 1 and K != x[a]:
                continue
            ans += str(a)
            K -= x[a]
            break
print(ans)


Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
INF = float('inf')
for i in range(1, N+1):
    t = -INF
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t

K = N
k = dp[N]
ans = ""
while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
for i in range(2, N+1):
    for a in A:
        if i >= x[a] and dp[i-x[a]] + 1 > dp[i]:
            dp[i] = dp[i-x[a]] + 1
K = N
ans = ''
while K > 0:
    for a in A:
        if dp[K] == dp[K-x[a]] + 1:
            if dp[K] == 1 and K != x[a]:
                continue
            ans += str(a)
            K -= x[a]
            break
print(ans)

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
INF = float('inf')
for i in range(1, N+1):
    t = -INF
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t

K = N
k = dp[N]
ans = ""
while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]
    
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
for i in range(2, N+1):
    for a in A:
        if i >= x[a] and dp[i-x[a]] + 1 > dp[i]:
            dp[i] = dp[i-x[a]] + 1
K = N
ans = ''
while K > 0:
    for a in A:
        if dp[K] == dp[K-x[a]] + 1:
            ans += str(a)
            K -= x[a]
            break
print(ans)

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
INF = float('inf')
for i in range(1, N+1):
    t = -INF
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t

K = N
k = dp[N]
ans = ""
while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A, reverse = True)
c = {}
for key in A:
    if key == 1:
        c[key] = 2
    elif key in [2, 3, 5]:
        c[key] = 5
    elif key == 4:
        c[key] = 4
    elif key in [6, 9]:
        c[key] = 6
    elif key == 7:
        c[key] = 3
    else:
        c[key] = 7

dp = [-1e9] * (N+1)
dp[0] = 0
for i in range(1, N+1):
    for key in c:
        if dp[i-c[key]] >= 0:
            dp[i] = max(dp[i-c[key]] + 1, dp[i])

K = N
while (K > 0):
    for key in c:
        if dp[K - c[key]] == dp[K] - 1:
            print(key, end = "")
            K -= c[key]
            break
print()

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
INF = float('inf')
for i in range(1, N+1):
    t = -INF
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t

K = N
k = dp[N]
ans = ""
while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break
print(ans)