N,M = map(int, input().split())

P = [list(map(int,input().split())) for i in range(M)]
s=[]
c=[]

for i in range(M):
    s.append(P[i][0])
    c.append(P[i][1])
A=[-1]*N

k=0
for i in range (M):
    if (A[s[i]-1]==-1) or (A[s[i]-1]==c[i]):
        A[s[i]-1]=c[i]
    else:
        k=1
        print(-1)
aa=0
if A[0]==0 and N>1:
    k=1
    print(-1)
if M==0:
    k=1
    if N==0:
        print(0)
    else:
        print(pow(10,(N-1)))

if k==0:
    for i in range (N):
        if A[i]==-1:
            A[i] = 0
            if A[0]==0:
                A[0]=1

        aa+=A[i]*pow(10,(N-i-1))

    print(aa)