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