n,m = map(int,input().split())

ans = True
s = [-1]*3
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1

    if (s[a] == -1) or (s[a] == b):s[a]= b
#すでに数字をいれている桁に別の数字が入る場合　
    else:ans = False


#最上桁が0
if s[0] == 0:
    ans = False

if ans :
    for i in range(1000):
        x = str(i)
        cnt = 0
        for dig in range(len(x)):
            if s[dig] == int(x[dig]):
                cnt+=1
            elif s[dig] == -1:
                cnt+=1
            else:
                continue
        
        if cnt == 3:
            print(i)
            break


else:
    print(-1)

