N, M = map(int, input().split())
num = [0, 0, 0]
condition = []
FLG = True

for i in range(M):
    a, b = map(int, input().split())
    condition.append((a-1, b))

for sc in condition:
    if num[sc[0]] and num[sc[0]] != sc[1]:
        FLG = False
        break
    else:
        num[sc[0]] = sc[1]

if FLG:
    ans = "".join(str(i) for i in num[3-N:])
    if ans == str(int(ans)):
        print(int(ans))
    else:
        print(-1)
        
else:
    print(-1)