from collections import defaultdict
N,M = map(int,input().split())
cand = defaultdict(set)

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

ans = ""
for i in range(1,N+1):
  if cand[i]:
    if len(cand[i])>1:
      print(-1)
      exit()
    else:
      for j in cand[i]:
          ans += str(j)
  else:
    ans += "0"
                    
if ans[0]== "0":
  print(-1)
else:
  print(ans)