N, M = map(int, input().split())
res = 0
c_list = [-1 for i in range(N)]

for i in range(M):
  s, c = map(int, input().split())

  if c_list[s - 1] != -1 and c_list[s - 1] != c:
    res = -1
  elif s == 1 and c == 0:
    res = -1
  else:
    c_list[s - 1] = c

if res == -1:
  pass
else:
  res = ''
  for i in range(N):
    if c_list[i] == -1:
      res += '0'
    else:
      res += str(c_list[i])

  if res[0] == '0':
    res = '1' + res[1::]

print(int(res))