N,M=map(int,input().split())
sc=[]
ans=[0,0,0]
for i in range(M):
    sc.append(list(map(int,input().split())))
for i in sc:
    if ans[i[0]-1] > i[1] or ans[i[0]-1]==0:
        ans[i[0]-1]=i[1]
stack=""
for i in ans:
    stack=stack+str(i)
stack=int(stack)
stack=str(stack)
if len(stack) == N and stack != "0":
    print(stack)
else:
    print(-1)