n,m=map(int,input().split())
ans=[]
check=True
for i in range(n):
  ans.append('0')
for i in range(m):
  s,c=map(str,input().split())
  if ans[int(s)-1]=='0':
    ans[int(s)-1]=c
    
  else:
    print(s,c)
    if ans[int(s)-1]!=c:
      check=False
  if s=='1' and c=='0':
    check=False
print(check)
if ans[0]=='0':
  ans[0]='1'

chu=''.join(ans)
if check:
  print(chu)
else:
  print(-1)

      