N, M = [int(i) for i in input().split()]
d = [0]*N
m = [0]*N
d[0] = 1
for i in range(M):
    idx, v = [int(i) for i in input().split()]
    idx-=1
    if idx==0:
        if v==0:
            print(-1)
            quit()
    if m[idx]==1:
        if d[idx]!=v:
            print(-1)
            quit()
    d[idx] = v
    m[idx] = 1
print(*d, sep='')