N,M = map(int,input().split())
d = [0 for _ in range(N)]
for _ in range(M):
    s,c = map(int,input().split())
    if d[s-1] == 0:
        d[s-1] = c
    else:
        if d[s-1]>c:
            d[s-1] = c
if d[0] == 0:
    print("-1")
else:
    print("".join(map(str,d)))