n, m = map(int, input().split())

tmp = ["0" for i in range(n)]
check = [0 for i in range(n)]
for i in range(m):
  s, c= map(str, input().split())
  check[int(s)-1]+=1
  tmp[int(s)-1] = c
flag = True

for i in check:
  if i >= 2:
    flag = False
    
    
ans = int("".join(tmp))
if len(str(ans)) == n and flag:
  print(ans)
else:
  print(-1)
