N,M = map(int,input().split())
S,C = [],[]
for _ in range(M):
  s,c = map(int,input().split())
  S.append(s)
  C.append(c)

INF = 10**15
ans = [INF] * N
for i in range(M):
  if S[i]-1 == 0 and C[i] == 0:
    continue
  ans[S[i]-1] = min(ans[S[i]-1], C[i])

if ans[0] == INF:
  print(-1)
else:
  print("".join([str(0) if i==INF else str(i) for i in ans ]))