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