N, M = map(int, input().split())
A = [0]*N
for i in range(M):
  s, c = map(int, input().split())
  if A[s-1] == 0:
    A[s-1] = c
  elif A[s-1] != c:
    print(-1)
    exit()

if A[0]>0:
  ans = A[0]*100+A[1]*10+A[2]
else:
  ans = -1
  
print(ans)