def main():
  N, M = map(int,input().split())
  dct = {}
  ans = [0]*N
  for _ in range(M):
    s, c = map(int,input().split())
    ans[s-1]=c
    if s not in dct:
      dct[s] = c
    else:
      if dct[s]!=c:
        print(-1)
        return 
  if ans[0]==0:
    ans[0]=1
  res = 0
  for i in ans:
    res*=10
    res+=i
  print(res)
  return
main()