import sys
N, M = map(int, input().split())

SClis = [] 
for _ in range(M):
    a, b = map(int, input().split())
    SClis.append([a,b])

ans = [0]*N


for singlelis in SClis:
    digits = singlelis[0]-1
    number = singlelis[1]

    if ans[digits] == 0:
        ans[digits] = number
    else:
        if ans[digits] > number:
            ans[digits] = number
        else:
            pass

if ans[0] == 0:
    print(-1)
    sys.exit()
else:
  kotae = ""
  for i in ans:
    kotae = kotae + str(i)
  
  print(int(kotae))