n,m=map(int,input().split())
num=[float('inf')]*n
for i,j in [list(map(int,input().split())) for _ in range(m)]:
  if i-1==0 and j==0:
    continue
  num[i-1] = min(num[i-1], j)
if len(num)==1:
  print(num[0])
else:
  if num[0]==float('inf') or num[0]==0: print(-1)
  else: print(*[0 if i==float('inf') else i for i in num],sep='')