N,M=list(map(int,input().split()))
number=[-1 for i in range(N)];
flag=True
for i in range(M):
    s,c=list(map(int,input().split()))
    if number[s-1]==-1:
        number[s-1]=c
    else:
        if number[s-1]!=c:
            flag=False

if number[0]==0&N!=1:
    flag=False
if not flag:
    print(-1)
else:
    if N==1:
        print(max(number[0],0))
    else:
        if number[0]==-1:
            number[0]=1

        for i in range(1,N):
            number[i]=max(number[i],0)

        T=""
        for i in range(0,N):
            T+=str(number[i])
        print(T)
