import numpy as np
N, M = map(int, input().split())
s, c = [], []
for i in range(M):
  tmp_s, tmp_c = map(int, input().split())
  s.append(tmp_s)
  c.append(tmp_c)

flag = 0
v_set = [999 for i in range(N)]
for i in range(M):
  if N == 1:	# 一桁のとき
    if v_set[0] == 999:
      v_set[0] = c[i]
      flag = 1
    elif v_set[0] != 999 and c[i] < v_set[0]:
      v_set[0] = c[i]
      flag = 1
  else:			# ２桁以上のとき
    if s[i] == 1 and c[i] == 0:
      flag = 0
      break
    elif v_set[s[i]-1] == 999:
      v_set[s[i]-1] = c[i]
      flag = 1
    elif v_set[s[i]-1] != 999 and c[i] < v_set[s[i]-1]:
      v_set[s[i]-1] = c[i]
      flag = 1
if flag == 0:
  print(-1)
else:
  for i in range(N):
    if v_set[i] == 999:
      v_set[i] = 0
  if N >= 2 and v_set[0] == 0:
    print(-1)
  else:
    out = ''
    for i in range(N):
      out += str(int(v_set[i]))
    print(out)
  