N,M = map(int,input().split())
array = [0]*N
T_F = True

for i in range(M):
  s,c = map(int,input().split())
  if s>N or (array[s-1] != 0 and array[s-1] !=c):
    T_F = False
    break
  else:
    array[s-1] = c
ans = 0
for i in range(N):
  ans += array[i]*(10**(N-i-1))
if T_F:
  if array[0]:
    print(ans)
  else:
    print(ans+10**(N-1))
else:
  print(-1)
  
  