n,m = map(int,input().split())
a = [-1]*n
l = list(list(map(int,input().split())) for i in range(m))
if n ==1 and all(s==1 and t==0 for s,t in l):
  print(0)
for j in l:
  s,c = j
  if s==1 and c ==0:
    print(-1)
    break
  if a[s-1]!=-1 and a[s-1]!=c:
    print(-1)
    break
  if a[s-1]==-1:
    a[s-1]=c
else:
  if a[0]==-1:
    a[0]=1
  for j in range(n):
    if a[j]==-1:
      a[j]=0
  print(*a,sep="")
