n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
a=[0]*(n+1)
if n!=1:
    a[1]=1
d=[-1]*(n+1)
flg=True
for i in range(m):
    s=sc[i][0]
    c=sc[i][1]
    if d[s]==-1 or a[s]==c:
        a[s]=c
        d[s]=0
    else:
        flg=False
ans=int("".join(map(str,a)))
if ans>=10**(n-1) and flg:
    print(ans)
else:
    print(-1)