N, M = map(int, input().split())
A = []
B = [0]*N
for m in range(M):
    s, c = map(int, input().split())
    A.append([s, c])
res = True
for a in A:
    if a[0] == 1:
        if B[0] != 0:
            if B[0] != a[1]:
                res = False
                break
        else:
            B[0] = a[1]
    elif a[0] == 2:
        if B[1] != 0:
            if B[1] != a[1]:
                res = False
                break
        else:
            B[1] = a[1]
    elif a[0] == 3:
        if B[2] != 0:
            if B[2] != a[1]:
                res = False
                break
        else:
            B[2] = a[1]
for b in range(len(B)-2):
    if B[b] == 0 and B[b+1] == 0 and B[b+2] == 0:
        res = False

B = str(B[0]) + str(B[1]) + str(B[2])
if res:
    print(B)
else:
    print('-1')