Harryxun/stf_run huggingface dataset:
length = raw_input()
count = length
answer = raw_input()

def compare(current, i):
  if current[i] < answer[i]:
    answer = current
  elif current[i] == answer[i]:
    compare(current, i+1)

while count > 0:
  current_word = raw_input()
  compare(current_word, 0)
  count -= 1

print answer
  

### FIXED CODE ###

s = []
n = input()
 
for i in range(n):
    x = raw_input()
    s.append(x)
 
s.sort()
 
print s[0]
a,b = map(int, input() .split())
if (a*b) % 2 == 1:
  print("Odd")
    else:
      print("Even")
	

### FIXED CODE ###

a,b = map(int, input() .split())
if (a*b) % 2 == 0:
  print("Even")
else:
  print("Odd")
s = input()
acgt = {'A', 'C', 'G', 'T'}
count = 0
temp_list= []

for c in s:
  if c in acgt:
    count += 1
  else:
    temp_list.append(count)
    count = 0

print(max(temp_list))

### FIXED CODE ###

s = input()
acgt = {'A', 'C', 'G', 'T'}
count = 0
temp_list= []

for c in s:
  if c in acgt:
    count += 1
  else:
    count = 0
  
  temp_list.append(count)
  
print(max(temp_list))
from sys import stdin, stdout
l = list(map(int, stdin.readline().rstrip().split(' ')))
print(l)
f=[]
i=-1
for n in (0,(len(l)-1)):
    f[n] = l[i]
    i = i+1
print(l)

### FIXED CODE ###

from sys import stdin, stdout
l = list(map(int, stdin.readline().rstrip().split(' ')))
f=[]
i=-1
n = 0
while(n<len(l)):
  f.append(l[i])
  i = i+1
  n= n+1
print(*f,sep=" ")
N = input()
A = list(map(int,input().split()))
ans = 0
for i in A:
  tmp = 0 
  while i % 2 == 0:
    i = i / 2
    tmp += 1
  ans = tmp if ans = 0 else min(ans,tmp)
print(ans)

### FIXED CODE ###

N = input()
A = list(map(int,input().split()))
B = []
for i in A:
  tmp = 0 
  while i % 2 == 0:
    i = i / 2
    tmp += 1
  B.append(tmp)
print(min(B))
import math
n = input()
a = list(map(int, input().split()))
flag = 0


for t in range(15):

    for i,j in enumerate(a):
        if j%2 == 0:
            a[i] = j/2

        else:
            flag = 1
            break

    if flag == 1:
        break

print(t)


### FIXED CODE ###

print(input().count("1"))
H, N = map(int, input().split())
A = list(map(int, input().split()))
atk = 0
for i in A:
    atk += i
if H > atk:
    print("No")
else:
    print("Yes")

### FIXED CODE ###

H, A = map(int, input().split())
count=0
while(H > 0):
    H -= A
    count += 1
print(count)
n,m = list(map(int,input().strip().split()))
h = list(map(int,input().split()))
temp = [1] * n
ans = int(0)
for i in range(m):
    a,b = list(map(int,input().strip().split()))
    if h[a-1] > h[b-1]:
        temp[b-1] *= 0
    elif h[a-1] == h[b-i]:
        temp[a-1] *= 0
        temp[b-1] *= 0
    else:
        temp[a-1] *= 0
ans += temp.count(1)
print(ans)

### FIXED CODE ###

n,m = list(map(int,input().strip().split()))
h = list(map(int,input().split()))
temp = [1] * n
ans = int(0)
for i in range(m):
    a,b = list(map(int,input().strip().split()))
    if h[a-1] > h[b-1]:
        temp[b-1] *= 0
    elif h[a-1] == h[b-1]:
        temp[a-1] *= 0
        temp[b-1] *= 0
    else:
        temp[a-1] *= 0
ans += temp.count(1)
print(ans)
S=list(input())
n=len(S)
ans='NO'
if S==list(reversed(S)):
    new=S[0:((n-1)//2)]
    if new==list(reversed(new)):
        new2=S[((n+3)//2):N+1]
        if new2==list(reversed(new2)):
            ans='YES'
print(ans)

### FIXED CODE ###

S=list(input())
n=len(S)
ans='No'
if S==list(reversed(S)):
    new=S[0:((n-1)//2)]
    if new==list(reversed(new)):
        new2=S[((n+3)//2)-1:]
        if new2==list(reversed(new2)):
            ans='Yes'
print(ans)
N, K = map(int, input().split())
A = list(map(int, input().split()))

t = 0
now = 1
footprint = [1]

while t < K:
  if A[now-1] not in footprint:
    footprint.append(A[now-1])
    now = A[now-1]
    t += 1
  else:
    s = footprint.index(A[now-1])
    l = t - s + 1
    e = (K-s) % l
    now = footprint[i+e]
    break

print(now)

### FIXED CODE ###

S = input()
T = input()
if S == T[:-1]:
  print("Yes")
else:
  print("No")
input(); print((lambda xs: max(xs) - min(xs))([int(x) for x in input().split()]))

### FIXED CODE ###

x = "".join(input().split())
x = int(x)
if x % 4 == 0:
    print("YES")
else:
    print("NO")
import numpy as np
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))
HH=np.zeros((N,N))
for i in range(M):
  A,B=list(map(int,input().split()))
  HH[A-1][B-1]=1
HH=HH+HH.T
count=0
for i in range(N):
  for j in range(N):
    if(HH[i][j]>0 and H[i]<=H[j]):
      count+=1
      break
print(N-count)

### FIXED CODE ###

import numpy as np
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))
F=[0]*len(H)
for i in range(M):
  A,B=list(map(int,input().split()))
  if(H[A-1]<H[B-1]):
    F[A-1]=1
  elif(H[A-1]>H[B-1]):
    F[B-1]=1
  else:
    F[B-1]=1
    F[A-1]=1
print(F.count(0))
n,m=map(int,input().split())
a=[0 for i in range(m)]
for i in range(n):
    k=list(map(int,input().split()))
    for g in range(k[0]):
        a[k[g]]+=1
s=0
for i in range(m):
    if a[i]==n:
        s+=1
print(s)


### FIXED CODE ###

n,m=map(int,input().split())
a=[0 for i in range(m)]
for i in range(n):
    k=list(map(int,input().split()))
    for g in range(k[0]):
        a[k[g+1]-1]+=1
s=0
for i in range(m):
    if a[i]==n:
        s+=1
print(s)
n=int(input())
a,b=map(int,input().split())
ans='NG'
for i in range(a,b+1):
  if i%k==0:
    ans='OK'
print(ans)

### FIXED CODE ###

n = int(input())
a,b = map(int, input().split())
flg = 0
for i in range(10000):
  if n * i >= a and n * i <= b:
    flg = 1
if flg == 1:
  print('OK')
else:
  print('NG')
N=int(input())
if N%2==0:
  ans=N
else:
  ans=2N
print(ans)

### FIXED CODE ###

N=int(input())
if N%2==0:
  ans=N
else:
  ans=2*N
print(ans)
a,b = map(int,imput().split()) 
   
if a*b % 2 == 0 :
    print("Even")
else:
    print ("Odd")

### FIXED CODE ###

a,b = map(int,input().split()) 
 
c = a*b  
if c%2 == 0 :
    print("Even")
else:
    print ("Odd")
a, b, k = map(int, input().split())
 
tmp = list(range(a, b+1))
for a in sorted(set(tmp[:k] + tmp[-k:])):
    print(a)

### FIXED CODE ###

A, B, K = map(int, input().split())

a_list = list(range(A, min(B, A+K)))
b_list = list(range(max(A, B-K+1), B+1))
for i in sorted(list(set(a_list + b_list))):
    print(i)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import collections


def process(commands):
    queue = collections.deque()
    for c in commands:
        if "insert" in c:
            queue.appendleft(int(c[7:]))
        elif "deleteFirst" in c:
            _ = queue.popleft()
        elif "deleteLast" in c:
            _ = queue.pop()
        elif "delete" in c:
            queue.remove(int(c[7:]))
    print(" ".join(list(map(str, queue))))


def main():
    n = int(input())
    process([input() for i in range(n)])


if __name__ == "__main__":
    main()

### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import collections


def process(commands):
    queue = collections.deque()
    for c in commands:
        if "insert" in c:
            queue.appendleft(int(c[7:]))
        elif "deleteFirst" in c:
            try:
                _ = queue.popleft()
            except IndexError as e:
                pass
        elif "deleteLast" in c:
            try:
                _ = queue.pop()
            except IndexError as e:
                pass
        elif "delete" in c:
            try:
                queue.remove(int(c[7:]))
            except ValueError as e:
                pass
    print(" ".join(list(map(str, queue))))


def main():
    n = int(input())
    process([input() for i in range(n)])


if __name__ == "__main__":
    main()
n, a = [int(i) for i in input().split()]
x = [int(i)-a for i in input().split()] 

max = max(x)

dp = [[0 for _ in range(2*n*max+1)] for _ in range(n+1)]

dp[0][n*max] = 1 

for i in range(1, n+1):
	for j in range(2*n*max+1):
		if j - x[i-1] < 0 or j - x[i-1] > 2*n*max:
			dp[i][j] = dp[i-1][j]
		else: 
			dp[i][j] = dp[i-1][j] + dp[i-1][j-x[i-1]]

print(dp[n][n*max]-1)







### FIXED CODE ###

n, a = [int(i) for i in input().split()]

x = [int(i) for i in input().split()] 
y = [int(i)-a for i in x] 


max = max(x)

dp = [[0 for _ in range(2*n*max+1)] for _ in range(n+1)]

dp[0][n*max] = 1 

for i in range(1, n+1):
	for j in range(2*n*max+1):
		if j - y[i-1] < 0 or j - y[i-1] > 2*n*max:
			dp[i][j] = dp[i-1][j]
		else: 
			dp[i][j] = dp[i-1][j] + dp[i-1][j-y[i-1]]

result = dp[n][n*max]-1

print(result)
import sys

n=int(raw_input())
buf =[[] for i in range(n)]

while True:
    text = raw_input().split()
    if text[0] == 'quit':
        break
    elif text[0] == 'push':
        buf[int(text[1])-1].append(text[2])
    elif text[0] == 'pop':
        print buf[int(text[1])-1][-1]
        buf[text[1]].pop()
    elif text[0] == 'move':
        buf[int(text[2])-1].append(buf[int(text[1])-1][-1])
        buf[int(text[1])-1].pop()

### FIXED CODE ###

import sys

n=int(raw_input())
buf =[[] for i in range(n)]

while True:
    text = raw_input().split()
    if text[0] == 'quit':
        break
    elif text[0] == 'push':
        buf[int(text[1])-1].append(text[2])
    elif text[0] == 'pop':
        print buf[int(text[1])-1][-1]
        buf[int(text[1])-1].pop()
    elif text[0] == 'move':
        buf[int(text[2])-1].append(buf[int(text[1])-1][-1])
        buf[int(text[1])-1].pop()
t=input()
s = list(t)


for i in range(len(t)):
    if s[i]=='?':
        if maemozi=='P':
            s[i]='D'
        else:
            s[i]='P'
    maemozi=s[i]


print("".join(s))

### FIXED CODE ###

t=input()
s = list(t)

# maemozi=''
# for i in range(len(t)):
#     if s[i]=='?':
#         if maemozi=='P':
#             s[i]='D'
#         else:
#             if i==len(t)-1:
#                 s[i]='D'
#             elif i==0:
#                 if s[i+1]=='D'or s[i+1]=='?':
#                     s[i]='P'
#                 else:
#                     s[i]='D'
#             else:
#                 if s[i+1]=='P':
#                     s[i]='D'
#                 else:
#                     s[i]='P'
#     maemozi=s[i]
for i in range(len(t)):
    if s[i]=='?':
        s[i]='D'

print("".join(s))
h, w, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0
total = 0
while total <= k:
  if a[0] < b[0]:
    total += a.pop(0)
  else:
    total += b.pop(0)
  ans += 1

if total > k:
  print(ans - 1)
else:
  print(ans)

### FIXED CODE ###

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
a = [0]
b = [0]
for i in range(n):
  a.append(a[i]+A[i])
for j in range(m):
  b.append(b[j]+B[j])
#print(a,b)
 
ans = 0
j = m
for i in range(n+1):
  if a[i] > k:
    break
  while (k - a[i]) < b[j]:
    j -= 1
    if j == -1:
      break
  
  ans = max(ans, i+j)
     
print(ans)
H, N = map(int, input().split())
damage = []
mp = []

for i in range(N):
    a, b = map(int, input().split())
    damage.append(a)
    mp.append(b)

dp = [[0]+[float("inf")]*H for _ in range(N + 1)]

for j in range(1, H + 1):
    if j % damage[0] == 0:
        x = j // damage[0]
    else:
        x = j // damage[0] + 1 
    dp[1][j] = x * mp[0]

for i in range(1, N):
    for j in range(H + 1):
        dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - damage[i]] + mp[i])
    
print(dp[N][H])

### FIXED CODE ###

H, N = map(int, input().split())
damage = []
mp = []
 
for i in range(N):
    a, b = map(int, input().split())
    damage.append(a)
    mp.append(b)
 
dp = [[0]+[float("inf")]*H for _ in range(N + 1)]

for i in range(N):
    for j in range(H + 1):
        if j - damage[i] >= 0:
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - damage[i]] + mp[i])
        else:
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][0] + mp[i])

print(dp[N][H])
num=[int(i) for i in input().split()]
for i in range(len(num)):
    for j in range(i+1,len(num)+1):
        if num[i]>num[j]:
            bigger = num[i]
            num[i]=num[j]
            num[j]=bigger
for i in range(len(num)):
    print(num[i],end="")

### FIXED CODE ###

num=[int(i) for i in input().split()]
for i in range(len(num)):
    for j in range(i+1,len(num)):
        if num[i]>num[j]:
            bigger = num[i]
            num[i]=num[j]
            num[j]=bigger
for i in range(len(num)-1):
    print(num[i],end=" ")
print(num[len(num)-1])
a=list (map(input()) )
 if(a[0]==a[5] &&a[1]==a[4]&&a[2]==a[3]):
        print("Yes" )
else:
       print("No")


### FIXED CODE ###

a=input()
b=input()
if(a[2]==b[0] and a[1]==b[1] and a[0]==b[2]):
    print('YES')
else:
    print('NO')
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M :
  print(0)
else:
  length = [0] * (M-1)
  for i in range(M-1):
    length[i](X[i+1]-X[i])
  length.sort()
  print(sum(length[:(M-N)]))

### FIXED CODE ###

N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
if N >= M :
  print(0)
else:
  length = [0] * (M-1)
  for i in range(M-1):
    length[i] = (X[i+1]-X[i])
  length.sort()
  print(sum(length[:(M-N)]))
from statistics import mean, median,variance,stdev
import sys
import math

x = input().split()
#y = input().split()
a = []
#for i in range(len(x)):
 #  a.append(int(x[i]))
if a[0] <1200:print("ABC")
else:print("ARC")

### FIXED CODE ###

from statistics import mean, median,variance,stdev
import sys
import math

x = input().split()
#y = input().split()
a = []
for i in range(len(x)):
   a.append(int(x[i]))
if a[0] <1200:print("ABC")
else:print("ARC")
day = input()
next_sunday = {1:"SAT",2:"FRI",3:"THU",4:"WED",5:"TUE",6:"MON",7:"SUN"}
value = next_sunday[day]
print(value)

### FIXED CODE ###

s = input()
lis = ["SUN","MON","TUE","WED","THU","FRI","SAT"]

ans = 7 - lis.index(s)
print(ans)
a, b = int(input())
print("Yay!") if a <= 8 and b <= 8 else print(":(
")

### FIXED CODE ###

a, b = map(int, input().split())
print("Yay!") if a <= 8 and b <= 8 else print(":(")
N=int(input())
##c=list(map(int, input().split()))
a=[]
b=[]
for i in range(N):
    a.append(int(input()))
    b.append(int(input()))
k=float(0)
for i in range(N-1):
    for j in range(i,N):
        k=k+((a[i]-a[j])**2+(b[i]-b[j])**2)**0.5

k=float(k*2/N)
print(k)




### FIXED CODE ###

N=int(input())
##c=list(map(int, input().split()))

a = [list(map(int, input().split())) for _ in range(N)]

k=0
for i in range(N):
    for j in range(N):
        if(i!=j):
            k=k+((a[i][0]-a[j][0])*(a[i][0]-a[j][0])+(a[i][1]-a[j][1])*(a[i][1]-a[j][1]))**0.5

print(k/N)
import sys
input = sys.stdin.readline
import math

def main():
    a, b, x = [int(x) for x in input().split()]
    b_now = x / (a * a)
    menseki = b_now * a
    ans_a = menseki * 2 / b

    # 三角形の場合
    if ans_a <= a:
        z = math.degrees(math.atan(ans_a / b))
        print(90 - z)
        exit()

    # 三角形 + 平行四辺形の場合
    else:
        menseki = a * b - menseki
        ans_b = menseki * 2 / a
        z = math.degrees(math.atan(a / ans_b))
        print(90 - z)
        exit()



if __name__ == '__main__':
    main()



### FIXED CODE ###

import sys
input = sys.stdin.readline
import math

def main():
    a, b, x = [int(x) for x in input().split()]
    b_now = x / (a * a)
    menseki = b_now * a
    ans_a = menseki * 2 / b

    if a * a * b == x:
        print(0)
        exit()

    if ans_a <= a:
        z = math.degrees(math.atan(ans_a / b))
        print(90 - z)
        exit()
    else:
        menseki = a * b - menseki
        ans_b = menseki * 2 / a
        z = math.degrees(math.atan(a / ans_b))
        print(90 - z)
        exit()



if __name__ == '__main__':
    main()
l = list(map(int,input().split()))

if l[1] < l[2]:
    print(0)
elif l[0] > l[4]:
    print(0)
else:
    l.sort()
    print(l[2]-l[1])

### FIXED CODE ###

l = list(map(int,input().split()))

if l[1] < l[2]:
    print(0)
elif l[0] > l[3]:
    print(0)
else:
    l.sort()
    print(l[2]-l[1])
from fractions import gcd
from functools import reduce

def main():
    N = int(input())
    A = list(map(int, input().split()))

    def pleaceAC():
        yield reduce(gcd, A[1:])
        yield reduce(gcd, A[:-1])
        for i in range(1,N-1):
            a = reduce(gcd, A[:i])
            b = reduce(gcd, A[i+i:])
            yield gcd(a, b)

    print(max(pleaceAC()))


main()

### FIXED CODE ###

from fractions import gcd
from itertools import accumulate

def main():
    N = int(input())
    A = list(map(int, input().split()))

    def pleaceAC():
        left = list(accumulate([0]+A, gcd))
        right = list(accumulate(reversed(A+[0]), gcd))
        for i in range(N):
            yield gcd(left[i], right[~(i+1)])

    print(max(pleaceAC()))


main()
N = int(input())
x = list(input())[::-1]
num = 0
nump = 0
numm = 0
pop_num = 0
for i in range(N):
    if x[i] == "1":
        pop_num += 1
for i in range(N):
    if x[i] == "1":
        num += pow(2,i,pop_num)
        num %= pop_num 
        nump += pow(2,i,pop_num+1)
        nump %= pop_num  + 1
        numm += pow(2,i,pop_num - 1)
        numm %= pop_num - 1



def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

x = x[::-1]
def calc(i,depth,n):
    if depth == 0:
        if x[i] == "1":
            tmp = numm
            tmp -=  2 ** (N - i - 1)
            tmp %= (pop_num - 1)
            return calc(i,depth+1,tmp)
        else:
            tmp = nump
            tmp +=  2 ** (N - i - 1)
            tmp %= (pop_num + 1)
            return calc(i,depth+1,tmp)
    else:
        if n == 0: return depth
        return calc(i,depth+1, n % popcnt(n))
        

for i in range(N):
    print(calc(i,0,0))



### FIXED CODE ###

N = int(input())
x = list(input())[::-1]
num = 0
nump = 0
numm = 0
pop_num = 0
for i in range(N):
        if x[i] == "1":
            pop_num += 1
for i in range(N):
    if x[i] == "1":
        num += pow(2,i,pop_num)
        num %= pop_num 
        nump += pow(2,i,pop_num+1)
        nump %= pop_num  + 1
        if pop_num-1 != 0:
            numm += pow(2,i,pop_num - 1)
            numm %= pop_num - 1



def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

x = x[::-1]
def calc(i,depth,n):
    if depth == 0:
        if x[i] == "1":
            tmp = numm
            if pop_num - 1 != 0:
                tmp -= pow(2,N-i-1,pop_num-1)
                tmp %= (pop_num - 1)
            else:
                return 0
            return calc(i,depth+1,tmp)
        else:
            tmp = nump
            tmp += pow(2,N-i-1,pop_num+1)
            tmp %= (pop_num + 1)
            return calc(i,depth+1,tmp)
    else:
        if n == 0: return depth
        return calc(i,depth+1, n % popcnt(n))
        

for i in range(N):
    print(calc(i,0,0))
n,m = map(int,input().split())
tr = [[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    tr[a-1].append(b)
    tr[b-1].append(a)
if not tr[0]:
    print('No')
else:
    mark = [10**7]*n
    mark[0] = -1
    cnt = 0
    i=0
    def mk(mark,i,cnt):
        for j in range(len(tr[i])):
            if tr[i][j]!=1:
                mark[tr[i][j]-1] = min(i+1,mark[tr[i][j]-1])
                cnt+=1
                if cnt == n-1:
                    return mark
            else:
                continue
        else:
            for j in range(len(tr[i])):
                mark = mk(mark,tr[i][j]-1,cnt)
            else:
                return mark
    mark=mk(mark,0,cnt)
    if 10**7 in mark:
        print('No')
    else:
        print('Yes')
        for i in range(1,n):
            print(mark[i])

### FIXED CODE ###

from collections import deque
 
n,m = list(map(int, input().split()))
put = [1]*(n+1)
 
ab = [[] for i in range(n+1)]
for i in range(m):
	a,b = map(int, input().split())
	ab[a].append(b)
	ab[b].append(a)

q = deque([1])
flg = [-1]*n
flg[0] = 0

while q:
	item = q.popleft()
	for i in ab[item]:
		if put[i]:
			flg[i-1]=item
			q.append(i)
			put[i]=0
 
if -1 in flg:
	print("No")
	exit()
 
print("Yes")
for i in range(1,len(flg)):
	print(flg[i])
N, M = map(int, input().split())
A = list(map(int, input().split()))
matchlist = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
numberlist = []
for i in range(M):
    numberlist.append([matchlist[A[i]], A[i]])
numberlist.sort(key = lambda x: (x[0], -x[1]))

ans = []
while N > 0:
    ans.append(numberlist[0])
    N -= ans[-1][0]
    if N < 0:
        N += ans.pop()[0]
        N += ans.pop()[0]
        numberlist.pop(0)

ans = [i[1] for i in ans]
ans.sort(reverse = True)
print("".join(map(str, ans)))


### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
matchlist = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
numberlist = []
for i in range(m):
    numberlist.append(matchlist[a[i]])
numberlist = set(numberlist)
#dp[i]:i本でのmax桁
dp = [-10000000]*(n+1)
dp[0] = 0
for i in range(n):
    for j in numberlist:
        if i+j <= n:
            dp[i+j] = max(dp[i+j], dp[i]+1)


ans = []
d = dp[n]
a.sort(reverse = True)
for i in range(d):
    for j in a:
        if n - matchlist[j] >= 0:
            if dp[n] == dp[n-matchlist[j]] + 1:
                n -= matchlist[j]
                ans.append(j)
                break
print("".join(map(str,ans)))
D,G = map(int,input().split())
PC = []

L = []

t = 10 ** 9
m = 0

for i in range(1,D + 1):
  p,c = map(int,input().split())
  s = 0
  pc = []
  for j in range(p):
    s += i * 100
    if j == p - 1:
      s += c
      L.append([j + 1,s])
    if s >= G and j + 1 < t:
      t = j + 1
    pc.append([j + 1,s])
  PC.append(pc)

def recur(problems):
　#探索の終了
  if len(problems) == D:
    ans = 10 ** 9
    score = 0
    times = 0
    #全部使用した問題セットの合計点と回答数を記録
    for j in range(D):
      if problems[j] == 1:
        score += L[j][1]
        times += L[j][0]
    #全問全回答の例を除く
    if score >= G:
      ans = min(ans,times)
      return ans
    #残りの数以上となる回答数のうち最小のものが見つかれば更新し
    #全回答の回答数に足す
    else:
      remain = G - score
      if remain <= max([L[i][1] for i in range(D) if problems[i] == 0]):
        for k in range(D):
          if problems[k] == 0:
            for l in range(len(PC[k])):
              if remain <= PC[k][l][1] and ans >= PC[k][l][0]:
                ans = PC[k][l][0]
        ans += times
        return ans
      else:
        return 10 ** 9
  
  else:
    #問題セットを全部使う
    ret1 = recur(problems + [1])
    #使わない
    ret2 = recur(problems + [0])
    
    return min(ret1,ret2)

print(recur([]))

### FIXED CODE ###

D,G = map(int,input().split())
PC = []

L = []

t = 10 ** 9
m = 0

for i in range(1,D + 1):
  p,c = map(int,input().split())
  s = 0
  pc = []
  for j in range(p):
    s += i * 100
    if j == p - 1:
      s += c
      L.append([j + 1,s])
    if s >= G and j + 1 < t:
      t = j + 1
    pc.append([j + 1,s])
  PC.append(pc)

def recur(problems):
  #探索の終了
  if len(problems) == D:
    ans = 10 ** 9
    score = 0
    times = 0
    #全部使用した問題セットの合計点と回答数を記録
    for j in range(D):
      if problems[j] == 1:
        score += L[j][1]
        times += L[j][0]
    #全問全回答の例を除く
    if score >= G:
      ans = min(ans,times)
      return ans
    #残りの数以上となる回答数のうち最小のものが見つかれば更新し
    #全回答の回答数に足す
    else:
      remain = G - score
      if remain <= max([L[i][1] for i in range(D) if problems[i] == 0]):
        for k in range(D):
          if problems[k] == 0:
            for l in range(len(PC[k])):
              if remain <= PC[k][l][1] and ans >= PC[k][l][0]:
                ans = PC[k][l][0]
        ans += times
        return ans
      else:
        return 10 ** 9
  
  else:
    #問題セットを全部使う
    ret1 = recur(problems + [1])
    #使わない
    ret2 = recur(problems + [0])
    
    return min(ret1,ret2)

print(recur([]))