import sys
N,M=map(int,input().split())
SC=dict()
for n in range(1,N+1):
    SC[n]=[]

for _ in range(M):
    s,c=map(int,input().split())
    SC[s].append(c)
if(N == 1):
    print(0)
    sys.exit()
ans = [i*10**(N - 1) for i in SC[1] if i != 0]
SC.pop(1)
for item in SC.items():
    keta=item[0]
    for kazu in item[1]:
        number = kazu * 10 ** (N - keta)
        for i in range(len(ans)):
            a = ans.pop(0)
            ans.append(a + number)
print(min(ans))
