N,M = map(int, input().split())
#for _ in range(M):
#    s, c = 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 k==0:
    for i in range (M):
        if A[i]==-1:
            A[i] = 0
        aa+=A[i]*pow(10,(M-i-1))

    print(aa)