N,M = map(int,input().split())
SC=[list(map(int,input().split())) for i in range(M)]

for ans in range(1000):
  if len(str(ans))!=N:
    continue
  f=1
  for i in range(M):
    if str(ans)[SC[i][0]-1]!=str(SC[i][1]):
      f=0
      break
  if f==1:
    print(ans);exit()
  
print(-1)