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

main()