N,M = map(int,input().split())
sc = [tuple(map(int,input().split())) for _ in range(M)]
sc = set(sc)

ans = -1
for i in range(1001):
    num = str(i).rjust(3,'*')
    for s,c in sc:
        if ( not num[s-1].isdigit() ) or ( int(num[s-1]) != c ):
            break
    else: ans = i
    if ans != -1:
        break

print(ans)
