n,m=map(int,input().split())
l=[0]*n
s_list=[]
x=0
for i in range(m):
  s,c=map(int,input().split())
  if s in set(s_list) and l[s-1]!=c:
    x=-1
    break
  else:
    s_list.append(s)
    l[s-1]=c
if x==-1 or (n>1 and l[0]==0):
  print(-1)
else:
  re=map(str,l)
  print(int(''.join(re)))