N,M = [int(x) for x in input().split()]       
s=list(N*"0")

for i in range(M):    
    x,y =[z for z in input().split()]

    if s[int(x)-1] == "0" or s[int(x)-1]==y:
        s[int(x)-1]=y 
    else:
        print(-1)
        exit()
if s[0]=="0" :print(-1)     
else:print(''.join(s))