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


li_num = [ list(map(int,input().split())) for i in range(m)]

invalid = False

#print(n)
#print(m)
#print(li_num)

li_ans = [0] * n
li_ans[0] = 1


arr = list(map(list, set(map(tuple, li_num))))
arr.sort(key=lambda x: x[0])

if [1,0] in arr:
  invalid = True

#print(arr)

arr_keta = [x[0] for x in arr if x[0] != 1]

if not invalid:
    if len(arr_keta) != len(set(arr_keta)):
        invalid = True

if invalid:
  print(-1)
else:
  for i in arr:
    s = i[0] - 1
    li_ans[s] = i[1]
  ans_num = int("".join(map(str, li_ans)))
  print(ans_num)
