def main():
  N,M=map(int, input().split())

  d={}
  for i in range(M):
    temps,tempc=map(int, input().split())
    if temps in d:
      if d[temps]!=tempc:
        print('-1')
        return
    else:
      if temps==1 and tempc==0:
        print('-1')
        return
      d[temps]=tempc
  if 1 not in d:
    print('-1')
    return
  ans=[]
  
  for i in range(N):
    if i+1 in d:
      ans.append(str(d[i+1]))
    else:
      ans.append(str(0))
  print(''.join(ans))
  return
main()