N,M = map(int,input().split())

LIST=[10]*N
for i in range(M):
    s,c = map(int,input().split())
    if LIST[s-1] > c:
        LIST[s-1]=c
for i in range(N):
    if LIST[i]==10:
        LIST[i]=0
if N==1:
    LIST2 = map(str, LIST) 
    print("".join(LIST2))
elif LIST[0]==0:
    print(-1)
else:
    LIST2 = map(str, LIST) 
    print("".join(LIST2))


