n,m=map(int,input().split())
num=[float('inf')]*n
for i,j in [list(map(int,input().split())) for _ in range(m)]:
  num[i-1] = min(num[i-1], j)
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='')