n,m=map(int,input().split())
x=["0" for _ in range(n)]
for _ in range(m):
  s,c=map(int,input().split())
  if x[s-1] != '0' and x[s-1] != str(c):
    print(-1)
    break
  else:
    x[s-1] = str(c)
if x[0]=='0':
  print(-1)
else:
  print("".join(x))