def main():
    N, M = map(int,input().split()) 
    s=[0]*M
    c=[0]*M
    for i in range(M):
        s[i],c[i]=map(int,input().split()) 
    
    number=[0]*N
    flag=[0]*N
    result=0
    for i in range(M):
        if number[s[i]-1]<c[i] and flag[(s[i]-1)]==1:
            continue
        number[(s[i]-1)]=c[i]
        flag[(s[i]-1)]=1

    if number[0]==0:
        print(-1)
        return
    else:
        for i in range(N):
            result += number[i]*10**(N-1-i)
        print(result)

    
main()