N, M = map(int, input().split())
a = [0]*N
for i in range(M):
    s, c = map(int, input().split())
    d = a[s-1]
    if d != 0:
        a[s-1] = min(c, d)
    else:
        a[s-1] = c
if a[0] != 0:
    print(*a, sep="") 
else:
    print("-1")