N, M = map(int,input().split())
s = []
c = []
for i in range(M):
  s_i, c_i = map(int,input().split())
  s.append(s_i)
  c.append(c_i)
  
n = [10] * N

for i in range(M):
  if n[s[i]-1] == 10:
    n[s[i]-1] = c[i]
  elif n[s[i]-1] == c[i]:
    pass
  else:
    print(-1)
    break
else:
  if N > 1 and n[0] == 0:
    print(-1)
  else:
    answer = 0
    for i in range(N):
      if i == 0:
        if n[0] == 10:
          answer += 1
        else:
          answer += n[0]
      else:
        answer *= 10
        if n[i] == 10:
          pass
        else:
          answer += n[i]
    else:
      print(answer)