
n,m=map(int,input().split())
a=[9]*n
b=[True]*n
if(n==1 and m==0):
    print(0)
    exit()
if(n!=1 and m==0):
    print(-1)
    exit()
for i in range(m):
    s,c=map(int,input().split())
    b[s-1]=False
    if(a[s-1]>=c):a[s-1]=c
for i in range(n):
    if(b[i]):a[i]=0
ans=""
for i in a:
    ans+=str(i)
if(len(str(int(ans)))==n):print((int(ans)))
else:print(-1)