n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(list(map(int, input().split())))
ans=[0]*n
for i in range(m):
    for j in range(i):
        if a[i][0]==a[j][0] and a[i][1]!=a[j][1]:
            print(-1)
            exit()
    ans[a[i][0]-1]=a[i][1]
g=True
for i in ans:
    if i!=0:
        g=False
if g:
    print(-1)
else:
    for i in range(len(ans)):
        if ans[i]==0 and (i==0 or ans[i-1]==0):
            print("")
        else:
            print(ans[i],end="")
