##入力
N, M = list(map(int,input().split()))
sc = [list(map(int,input().split())) for _ in range(M)]
numl = [0 for _ in range(N)]
flag = 0
s = [sc[i][0] for i in range(M)]
c = [sc[i][1] for i in range(M)]
##数字を桁ごとにリストに入れる
for i in range(M):
  numl[s[i]-1] = c[i]
##最初の桁が0で2桁以上ならだめ
if numl[0] == 0 and N >= 2:
  flag += 1
##同じ桁で違う数字を指定されたらだめ
for i in range(0, M-1):
  for j in range(i+1, M):
    if s[i] == s[j] and c[i] != c[j]:
      flag += 1

if flag != 0:
  print(-1)
else:
  Numl = [str(a) for a in numl]
  num=''.join(Numl)
  print(num)