n,m=map(int,input().split())
num=[0 for i in range(n)]
s=[]
c=[]
for i in range(m):
    si,ci=map(int,input().split())
    s.append(si)
    c.append(ci)

def ans():
    for i in range(m):
        if num[s[i]-1]!=0 and num[s[i]-1]!=c[i]:
            print(-1)
            return
        num[s[i]-1]=c[i]
    if num[0]==0:
        print(-1)
        return
    for i in range(n):
        print(num[i],end="")
    print()

ans()