n,m = map(int, input().split())
a = [0]*n
ans = 1
for i in range(m):
  s,c = map(int,input().split())
  if a[s-1] == 0 or a[s-1] == c:
    a[s-1] = c
  else:
    ans = -1
    break
if ans != -1 and a[0] > 0:
  a = map(str, a)
  print("".join(a))
else:
  print(-1)