n, m = [int(i) for i in input().split()]
f = True
d = {}
for _ in range(m):
  s, c = [int(i) for i in input().split()]
  if s in d.keys() and d[s] != c:
    f = False
  d[s] = c
  
ans = ''


if n != 0:
  if 1 in d.keys():
    if d[1] == 0:
      f = False
    else:
      ans = str(d[1])
  else:
    ans = '1'
  for i in range(n-1):
    if i+2 in d:
      ans += str(d[i+2])
    else:
      ans += '0'
else:
  if 1 in d.keys():
    ans = str(d[1])
  else:
    ans = '0'
    
if f:
  print(ans)
else:
  print(-1)

