n,m = map(int,input().split())
S = []
C = []
for i in range(m):
    s,c= map(int,input().split())
    S.append(s)
    C.append(c)
ans = [0]*n
ref = [0]*n
flag = 1

for i in range(m):
    if ref[S[i]-1] == 0:
        ans[S[i]-1] = C[i]
        ref[S[i]-1] = 1
    elif ref[S[i]-1] == 1 and ans[S[i]-1]==C[i]:
        pass
    else:
        flag = 0
        break

if flag==1:
    if n>1 and ans[0]==0:
        print(-1)
    elif n>1 and ans[0]!=0:
        anss = ""
        for s in ans:
            anss += str(s)
        print(int(anss))
    else:
        print(ans[0])
else:
    print(-1)


