N, M = map(int, input().split())

S = [0] * M
C = [0] * M

Q = [None] * 3

for i in range(M):
    S[i], C[i] = map(int, input().split())


is_exist = True
for i in range(M):
    if S[i] == 1 and C[i] == 0:
        is_exist = False

    for j in range(3):
        if S[i] == j + 1:
            if Q[j] == None:
                Q[j] = C[i]
            elif Q[j] != C[i]:
                is_exist = False

ret = ""
if is_exist:
    for i in range(3):
        if i == 0 and Q[i] == None:
            ret = ret + "1"
        elif Q[i] == None:
            ret = ret + "0"
        else:
            ret = ret + str(Q[i])
    print(ret)
else:
    print("-1")
