n,m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
w = [0]*n
w.sort()
a = -1
b = -1
z = 'YES'
for h in range(m):
    if sc[h][0] != a and sc[h][1] != b:
        w[sc[h][0]-1] = sc[h][1]
        a = sc[h][0]
        b = sc[h][1]
    elif sc[h][0] == a and sc[h][1] != b:
        z = 'NO'
        break
if z == 'NO':
    print(-1)
else:
    if w[0] == 0:
        print(-1)
    else:
        x = ""
        for j in w:
            x += str(j)
        print(x)