N,M=map(int, input().split())
s=[0]*M
c=[0]*M
for i in range(M):
    s[i],c[i]=map(int, input().split())
T=s
#print(T)
A=['']*3
for i in range(M):
    if A[T[i]-1]=='':
        A[T[i]-1]=c[i]
    elif A[T[i]-1]==c[i]:
        continue
    else:
        print(-1)
        exit()
#print(A)
a=''
for i in range(len(A)):
    if A[i]=='':
        A[i]=0
    if len(a)==0 and A[i]==0:
        continue
    a+=str(A[i])
if a=='':
    print(0)
else:
    print(a)
