stdin = open(0).read().split('\n')
N, M = map(int,stdin[0].split())
if M ==0:
    num=['0']*N
    if N!=1:
        num[0]='1'
    ans = "".join(num)
    print(int(ans))
else:
    num=['a']*N
    flag = True
    for i in range(M):
        s, c = stdin[i+1].split()
        if N!=1 and s=='1' and c=='0':
            flag = False
            break            
        elif not num[int(s)-1].isdecimal():
            num[int(s)-1]=c
        elif num[int(s)-1]!=c:
            flag = False
            break
    if num[0]=='a':num[0]='1'
    ans = "".join(num).replace('a', '0')
    print(int(ans) if ans[0]!='0' and flag else -1)