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
  
    
#未指定文字の置き換え。最上位桁は"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 if ans != 0 else -1)
