n,m = map(int,input().split())
ans = [0 for _ in range(n)]

z = 0
done = []
for _ in range(m):
  s,c = map(int,input().split())
  if not s in done:
    ans[s-1] = c
    done.append(s)
  else:
    if ans[s-1] != c:
      print(-1)
      z = 1
      break
      
if n != 1 and ans[0] == 0 and z ==0:
  print(-1)
else:
  ans = map(str,ans)
  if z ==0:
    print(int(''.join(ans)))