n, m = map(int, input().split())
lst = [-1] * n
flag = False
for i in range(m):
  s, c = map(int, input().split())
  if lst[s-1] > 0 and c != lst[s-1]:
    flag = True
  lst[s-1] = c
if flag or lst[0] == 0:
  print(-1)
else:
  ans = ''
  for i in range(n):
    if lst[i] >= 0:
      ans += str(lst[i])
    elif n != 1 and i == 0:
      ans += '1'
    else:
      ans += '0'
  print(ans)