N,M = map(int,input().split())
sl = [list(map(int,input().split())) for _ in range(M)]

for i in range(10**(N-1),10**N):
    str_i = str(i)
    count = 0
    for s,c in sl: 
        if(len(str_i)>=s):
            if(str_i[s-1]==str(c)):
                count += 1
        else:
            break
    
    if(count==len(sl)):
        print(i)
        exit(0)

print(-1)
