n,m=map(int,input().split())
ans=[0 for i in range(n)]
f=[[True] for i in range(n)]
for i in range(m):
    s,c=map(int,input().split())
    if f[s-1]==False:
        if ans[s-1]!=c:
            print(-1)
            sys.exit()
    if f[s-1]:
        f[s-1]=False
    ans[s-1]=c
if ans[0]==0:
    print(-1)
    sys.exit()
a=map(str,ans)
print("".join(a))