n,m=map(int, input().split())
list1=[list(map(int,input().split())) for i in range(m)]

ans=['x']*n
non=0
for i in range(m):
    if ans[list1[i][0]-1]!='x':
        if int(ans[list1[i][0]-1])==list1[i][1]:
            continue
        else:
            non=-1
            break
    else:
        ans[list1[i][0]-1]=str(list1[i][1])

if non==-1:
    print(-1)
else:
    if ans[0]=='0':
        print(-1)
    else:
        if 'x' in ans:
            if ans[0]=='x':
                ans[0]='1'
            for i in range(n):
                if ans[i]=='x':
                    ans[i]='0'
        K=''
        for i in range(n):
            K+=ans[i]
        print(int(K))