n, m = map(int, input().split())
apple = []
for _ in range(m):
    apple.append(list(map(int, input().split())))
count = 0
orange = [1] + [0]*(n-1)
a = "a"
for i in apple:
    for j in apple:
        if i[0] == j[0] and i[1] != j[1]:
            count = 1
            break
        else:
            orange[i[0] - 1] = i[1]
if count == 1:
    print("-1")
else:
    if len(orange) >= 2 and orange[0] == 0:
        print("-1")
    else:
        for i in orange:
            a += str(i)
        print(a[1:])
