N,M = map(int,input().split())
ans = ['-1']*(N+1)
flg = True
for i in range(M):
  d,n = map(int,input().split())
  if (ans[d]=='-1') or (ans[d]==str(n)):
    ans[d] = str(n)
  else:
    flg = False
    break
if flg:
  ans = ans[1:]
  if ans[0]=='0':
    print(-1)
  else:
    ans = ''.join(ans)
    ans = ans.replace('-1','0')
    if N==1:
      print(int(ans))
    elif ans[0]=='0':
      ans = ans[1:]
      print(''.join(['1',ans]))
    else:
      print(int(ans))
else:
  print(-1)
