n,m=map(int,input().split())
num=[0 for i in range(n)]
flag=[False 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 s[i]-1==0 and c[i]==0:
            continue
        if flag[s[i]-1]==False:
            num[s[i]-1]=c[i]
            flag[s[i]-1]=True
        else:
            if num[s[i]-1]==c[i]:
                continue
            print(-1)
            return
#        else:
#            num[s[i]-1]=min(c[i],num[s[i]-1])
    if n!=1 and num[0]==0:
        print(-1)
        return
    for i in range(n):
        print(num[i],end="")
    print()

ans()