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

s = []
c = []
for i in range(M):
    a, b = map(int, input().split())
    s.append(a)
    c.append(b)
#print(s)
#print(c)
A=[0]*N
flag=1


for i in range(M):
  if A[s[i]-1]!=0 and A[s[i]-1]!=c[i]:
    flag=0
  else:
    A[s[i]-1]=c[i]
    
if M==0:
  A[0]=1

ans=''
if flag==1:
  for i in range(N):
    ans+=str(A[i])
  print(int(ans) if ans[0]!='0' else '-1')
               
else:
  print(-1)
