import itertools
n, m = map(int, input().split())
memo = dict()
ans = 100000000
arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for _ in range(m):
  s, c = map(int, input().split())
  if s in memo:
    if not memo[s]==c:
      ans=-1
  elif not s in memo:
    memo[s]=c

for per in itertools.permutations(arr, n):
  # 702
  check = True
  if per[0]==0:
    continue
  for key in memo:
    if not memo[key] == per[key-1]:
      check=False
  if check:
    s = ""
    for p in per:
      s+=str(p)
    ans = min(ans, int(s))
    break
if ans==100000000:
  ans=-1
print(ans)
  