n,m=map(int,input().split())
num=["0"]*n
ans=0
for i in range(m):
    s,c=input().split()
    s=int(s)
    if s==0 and c=="0":
        ans=-1
    elif num[s-1] != "0":
        num[s-1] = c
    else:
        if num[s-1] != c:
            ans=-1

if num[0] == "0":
    num[0] = "1"
if ans==-1:
    print(ans)
else:
    print(int("".join(num)))
