n,m = map(int,input().split())
l = []
ed = []
flag = 0
for i in range(n):
  l.append(0)
  ed.append(0)
for i in range(m):
  s,c = map(int,input().split())
  if ed[s-1] == 1:
    if l[s-1] != c:
      flag = 1
  l[s-1] = c
  ed[s-1] = 1
if l[0] == 0:
  print(-1)
elif flag == 1:
  print(-1)
else:
  st = ""
  for i in l:
    st += str(i)
  print(int(st))