def do():
    (n,m)=map(int,input().split())
    d=[]
    k=0
    l=[]
    for i in range(m):
        (a,b)=map(int,input().split())
        d.append((a,b))
        l.append(a)
    d.sort()
    l=set(l)
    if len(l)==n:
        for j in range(len(d)):
            if d[j][0]==d[j-1][0]:
                k=k*10+0
            else:
                 k=k*10+d[j][1]
        return k
    else:
        return "-1"

print(do())