N,M = map(int,input().split())
ret = ['a','a','a']
for _ in range(M):
  s,c = map(int,input().split())
  if ret[s-1] not in ['a', c]:
    print(-1)
    exit()
  ret[s-1] = c
ans = ''
for i in range(3):
  if ret[i] != 'a':
    ans += str(ret[i])
  else:
    if i == 0:
      ans += '1'
    else:
      ans += '0'
print(int(ans))