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

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

  #先頭ゼロ判定
  #if i == 0 and c == 0:
  #  ans = -1
  #  break

  #前回値判定
  if TMP[s-1] == '*' or TMP[s-1] == c:
    TMP[s-1] = c
  else:
    ans = -1
    break
  
    
#未指定文字の置き換え。最上位桁は"1"に、以外は"0"に置き換える。
if ans != -1:
  for x in range(N):
    if TMP[x] == '*' and x == 0:
      TMP[x] = 1
    elif TMP[x] == '*' and x > 0:
      TMP[x] = 0

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