N , M = map(int,input().split())
sc = sorted([list(map(int,input().split())) for _ in range(M)], reverse=True)
num = ["0"] * 3

is_low_bit = -1
for i in range(M - 1, 0 , -1):
    if sc[i][0] == sc[i - 1][0] and sc[i][1] != sc[i - 1][1]:
        print("-1")
        exit()


for s, c in sc:
    if (num[2] != "0" and c == 0) or (num[1] != "0" and s == 0 and c == 0):
        print('-1')
        exit()
    else:
        num[s - 1] = str(c)

for i in range(2):
    if num[0] == "0":
        num.pop(0)
    else:
        break

if len(num) == N:
    print("".join(num))
else:
    print("-1")
