n,m=map(int,input().split())

result="*"*n

for _ in range(m):
    s,c=map(int,input().split())
    if result[s-1]=="*":
        result=result[:s-1]+str(c)+result[s:]
        #print(result)
    elif result[s-1]!=str(c):
        print(-1)
        exit()

if result[0]=="0":
    print(-1)
    exit()
result2=result.replace("*","0")

result2=int(result2)
result2=str(result2)


if len(result2)==n:
    print(int(result2))
else:
    temp=10**(n-1)
    print(int(result2)+temp)
    
