N, M = map(int, input().split())

flag = 0
x = [-1] * N
for m in range(M):
  s, c = map(int, input().split())
  if (x[s-1] != -1) & (x[s-1] != c):
    flag = 1
  else:
    x[s-1] = c
    
ans = 0
for n in range(N):
  if x[n] != -1:
    ans += 10**(N-n-1) * x[n]

if ans >= 10**(N-1):
  print(ans)
else:
  print(-1)