n,m = map(int,input().split())
l = [0]*n
ans = ''

for i in range(m):
  s,c = map(int,input().split())
  if l[s-1] == c or l[s-1] == 0:
    l[s-1] = c
  else:
    ans = '-1'

if n != 1 and l[0] == 0:
  ans = '-1'
else:
  for a in l:
    ans = ans + str(a)

print(ans)