N,M=list(map(int,input().split()))
ans=-1
tmp=[]
A=[]
S=[]
C=[]

for m in range(M):
  s,c=list(map(int,input().split()))
  S.append(s)
  C.append(c)

for i in range(10**(N-1),10**N):
  tmp.clear()
  for m in range(M):
    try:
      if int(list(str(i))[S[m]-1])==C[m]:
        tmp.append(True)
      else:
        tmp.append(False)
    except IndexError:
      tmp.append(False)
#  print(tmp.count(True))
  if tmp.count(True)==M:
    if int(list(str(i))[0])!=0 or N==1:
      ans=i
#    print(ans)
    break
  
if M==0:
  ans=10**(N-1)
  if N==1:
    ans=0
print(ans)
      