n,m = map(int,input().split())

digit = [0 for i in range(n+1)]
for i in range(m):
  s,c = map(int,input().split())
  if digit[s] != 0 and digit[s]!=c:
    print('-1')
    exit()
  if n>1 and s==1 and c==0:
    print('-1')
    exit()
  digit[s] = c
ans = ''
for i in range(1,len(digit)):
  ans += str(digit[i])
print(ans)
