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

ans = list('0'*m)

for i in range(m):
  a, b = map(int, input().split())
  
  if a==1 and b ==0:
    print(-1)
    exit()
  if ans[a-1] != '0' and ans[a-1] != str(b):
    print(-1)
    exit()
    
  ans[a-1] = str(b)

ans = int(''.join(ans))
print(ans)
