N, M = map(int, input().split())
s = [0]*M
c = [0]*M
for i in range(M):
    s[i], c[i] = map(int, input().split())

ans = [0]*N 
   
for i in range (0,M):
  if ans[s[i]-1] == 0:
    ans[s[i]-1] = c[i]
  else:
    if ans[s[i]-1] != c[i]:
      ans = [-1]
      break
if ans[0] == 0:
  ans = [-1]
  
a = map(str, ans)
p_ans = ''.join(a)      
print(p_ans)