N,M=map(int,input().split())
s=[]
c=[]
for _ in range(M):
    S,C=map(int,input().split())
    s.append(S)
    c.append(C)

num=[10]*N

for i in range(M):
    if s[i]==1 and c[i]==0:
        num="-1"
        break
    elif num[s[i]-1]==10:
        num[s[i]-1]=c[i]
    elif num[s[i]-1]!=10 and num[s[i]-1]!=c[i]:
        num="-1"
        break
if num=="-1":
    print(num)
else:
    for l in range(N):
        if num[l]==10:
            num[l]=0
    if num[0]==0:
        num[0]=1
    for j in range(N):
        print(num[j],end="")