N,M = map(int,input().split())
array = [ list(map(int,input().split())) for _ in range(M) ]
ans = [10]*N
count = 0
for i in range(M):
  if ans[ array[i][0] - 1 ] != array[i][1]:
    count += 1
  ans[ array[i][0] - 1 ] = array[i][1]
if count > 3:
  print(-1)
elif ans[0] == 0 and len(ans) > 1:
  print(-1)
else:
  for i in  range(N):
    if ans[i] == 10:
      ans[i] = 0
  ans = map(str,ans)
  answer = ''.join(ans)
  print(int(answer))