n,m = map(int,input().split())
l = [-1] * n
for i in range(m):
  s,c = map(int,input().split())
  if n != 1 and [s,c] == [1,0]:
    print(-1)
    exit()
  if l[s-1] == -1 or l[s-1] == c:
    l[s-1] = c
  else:
    print(-1)
    exit()
print(*[i if i != -1 else 0 for i in l],sep='')