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

S = []
C = []

for _ in range(M):
    s,c = map(int, input().split())
    S.append(s)
    C.append(c)

ans = [float('inf')]*N

for s,c in zip(S,C):
    s = int(s) - 1
    if ans[s] > int(c):
        ans[s] = int(c)

if ans[0]==float('inf'):
    print(-1)
else:
    for i in range(N):
        if ans[i]==float('inf'):
            ans[i] = 0
    print(*ans, sep="")