N,M  = (int(x) for x in input().split())
Num  = list('?'*N)
Flag = True

if len(Num)==1:
    for T in range(0,int(M)):
        s,c = input().split()
        if Num[int(s)-1]!='?' and Num[int(s)-1]!=c:
            Flag = False
            break
        else:
            Num[int(s)-1] = c
            
    if Flag:
        if Num[0]=='?':
            Num[0] = '0'
        print(''.join(Num))
    else:
        print('-1')
else:
    for T in range(0,int(M)):
        s,c = input().split()
        if (Num[int(s)-1]!='?' and Num[int(s)-1]!=c) or ([s,c]==['1','0']):
            Flag = False
            break
        else:
            Num[int(s)-1] = c
    
    if Flag:
        if Num[0]=='?':
            Num[0] = '0'
            Num = ['0' if x=='?' else x for x in Num]
        else:
            Num = ['0' if x=='?' else x for x in Num]
        print(''.join(Num))
    else:
        print('-1')