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

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

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

if ans != '-1':
  # *を0で置き換え
  for x in range(N):
    if TMP[x] == '*':
      TMP[x] = 0

  ans = int(''.join(map(str, TMP)))

print(ans)