n,m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
sc1 = []
sc1 = [x for x in sc if x not in sc1 and not sc1.append(x)]
if [1,0] in sc1 or n < len(sc1):
    print(-1)
else:
    sc1.sort()
    w = ['0']*n
    j = -1
    for i,h in sc1:
        if i != j:
            w[i-1] = str(h)
            j = i
        else:
            w = -1
            break
    if w == -1:
        print(-1)
    else:
        print("".join(w))