#graph implementation
import math
n,m=map(int,input().split())
ans=[0]*n
for i in range(m):
    s,c=map(int,input().split())
    if ans[s-1]==0:
            ans[s-1]=c
    else:
        if ans[s-1]>=c and c>0:
            ans[s-1]=c
if len(ans)<3:
    if n==2 and ans[0]==ans[1]==0:
        print(-1)
        exit(0)
    for i in ans:
        print(i,end="")
elif ans[0]==0:
    print(-1)
else:
    for i in ans:
        print(i,end="")
print()
