N,M=map(int,input().split())
d={}
for i in range(M):
  s,t=map(int,input().split())
  if s in d:
    if d[s]!=t:
      print('-1')
      exit()
  if s==1:
    if t==0:
      print('-1')
      exit()
  d[s]=t
for i in range(1,N):
  if i not in d:
    d[i]=0
#print(d)
L=[]
for i in d.values():
  L.append(str(i))
print(''.join(L))