N, M = (int(x) for x in input().split(' '))
TMP = [0,0,0]
ans = 0

#ループで探しながら処理 
for _ in range(M):
  s, c = (int(x) for x in input().split(' '))

  #前回値判定
  if TMP[s-1] == 0 or TMP[s-1] == c:
    TMP[s-1] = c
  else:
    ans = -1
    break

if ans != -1:
	ans = int(''.join(map(str, TMP)))

print(ans if ans != 0 else -1)