n,m=map(int,input().split())
list=[list(map(int,input().split())) for _ in range(m)]
flag=False
ans=['10']*n
for i in range(m):
  if (list[i][0]==n and list[i][1]!=0) or (n==1 and list[i][0]==n and list[i][1]==0):
    flag=True
  ans[list[i][0]-1]=str(min(int(ans[list[i][0]-1]),list[i][1]))
if flag==True:
  for j in range(n):
    if ans[j]=='10':
      ans[j]='0'
  print(''.join(ans))
else:
  print('-1')