def do():
    (n,m)=map(int,input().split())
    d=[]
    k=0
    for i in range(m):
        (a,b)=map(int,input().split())
        d.append((a,b))
    d.sort()
    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]
    if len(str(k))==n:
        return k
    else:
        return "-1"

print(do())