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

num = [-1] * n
ans = -1
f = 1

for _ in range(m):
  s, c = map(int, input().split())
  if s == 1 and c == 0:
    f = 0
    break
    
  i = num[s - 1]
  if i == -1:
    num[s-1] = c
  elif i == c:
    continue
  else:
    f = 0
    break
  
if num[0] == -1:
  num[0] = 1
  
if f:
  num = [0 if n == -1 else n for n in num]
  ans = ''.join(map(str, num))
  
print(ans)