import copy
def main():
    n,m = map(int,input().split())
    ans = [10 for i in range(n+1)]
    num = 0
    if m==0:
        if n==1:
            print(0)
        else:
            print(10**(n-1))
        exit()
    for i in range(m):
        s,c = map(int,input().split())
        if ans[s-1] != 10:
            print('-1')
            exit()
        ans[s-1] = min(ans[s-1],c)
    
    for i in range(n):
        if ans[i]==10:
            ans[i] = 0
        num += ans[i]*(10**(n-i-1))
    #print(num)
    cnt = 1
    copy_ans = copy.deepcopy(num)
    while copy_ans >= 10:
        copy_ans /= 10
        cnt += 1
    if cnt==n:
        print(num)
    else:
        print('-1')

main()