n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]

for i in range(1000):
    num = list(str(i))
    if n != len(num):
        continue

    for s,c in sc:
        if num[s-1] != str(c):
            break
    else:
        print(i)
        exit()
    continue



print(-1)