N,M = map(int,input().split())
a = list("0"*N)
for i in range(M):
    s,c = map(int,input().split())
    if int(a[s-1])>c or int(a[s-1])==0:
        a[s-1] = str(c)
ans = "".join(a)
if ans[0]!="0":
    print(ans)
else:
    print(-1)