n,m=map(int,input().split())
l=[0]*(n)
for i in range(m):
  s,c=map(int,input().split())
  if l[s-1]!=0 and l[s-1]!=c:
    print(-1)
    exit()
  elif l[s-1]==0:
    l[s-1]=c
if l[0]==0 and sum(l)>0:
  print(-1)
  exit()
if sum(l)==0:
  print(0)
for i in range(len(l)):
  l[i]=str(l[i])
print(''.join(l))