N,M = map(int, input().split())
S = []
C = []

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

Query = list(zip(S,C))
ans = [float('inf')]*N

for s,c in Query:
    index = int(s)-1
    num   = int(c)
    if ans[index]>c:
        ans[index] = c

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