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

for _ in range(M):
    i, digit = map(int, input().split())
    i -= 1
    if num[i] is not None and num[i] != digit:
        FLG = False
    else:
        num[i] = digit

if FLG:
    for i,digit in enumerate(num):
        if i == 0 and digit is None:
            num[i] = "1"
        elif i != 0 and digit is None:
            num[i] = "0"
        else:
            num[i] = str(digit)
            
    ans = "".join(num)
    if ans == str(int(ans)):
        print(int(ans))
    else:
        print(-1)

else:
    print(-1)
