n, m = map(int, input().split())
if n == 1 and m == 0:
  print(0)
  exit()
  
answer = [-1]*n

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

if answer[0] == -1:
  answer[0] = 1
for j in range(n):
  if answer[j] == -1:
    answer[j] = 0
    
answer = [str(x) for x in answer] 

print(int(''.join(answer)))

