N, M = map(int, input().split())
check = [10] * N
ans = 0

i = 0
while ans != -1 and i < M:
  S, C = map(int, input().split())
  if check[S-1] != 10:
    if check[S-1] != C:
      ans = -1
  else:
    check[S-1] = C
  i += 1
  
if N != 1:
  if check[0] == 0:
    ans = -1
    
if ans != -1:
  for i in range(N):
    if check[i] != 10:
      ans += check[i] * 10 ** (N-i-1)
    
print(ans)