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

if num[0]==-1:
    num[0]=1

if num[0]==0:
    print(-1)
    exit()

st=""
for i in range(n):
    if num[i]!=-1:
        st+=str(num[i])
    else:
        st+="0"

print(st)