N, M = map(int, input().split())
A=[0]*N
ans=0
e=0
for i in range(M):
  s, c = map(int, input().split())
  if(s==1 and c==0):
    print(-1)
    e=1
    break
  if A[s-1]==0 or A[s-1]==c:
  	A[s-1]=c
  else:
    print(-1)
    e=1
    break
if A[0]==0:
  A[0]=1
for i in range(N):
  ans+=A[i]*(10**(N-i-1))
if e==0:
  print(ans)
  
          