N,M = map(int,input().split())
keep_value = [None]*N
check = False
for i in range(M):
    s,c = map(int,input().split())
    if((keep_value[s-1]!=None) and (keep_value[s-1]!=c)):
        print('-1')
        exit()
    else:
        keep_value[s-1]=c
if(None not in keep_value):
    print(''.join(map(str,keep_value)))
else:
    if(N>2 and keep_value[0]==0):
        print('-1')
    else:
        if(keep_value[0]==None):
            keep_value[0]=1
        keep_value=[0 if i==None else i for i in keep_value]
        print(''.join(map(str,keep_value)))