#N=int(input())
#N,M=map(int, input().split())
#L=list(map(int, input().split()))
N,M=map(int, input().split())
Ans=N*[-1]
for i in range(M):
  s,c=map(int,input().split())
  s-=1
  if c==0 and s==0:
    print(-1)
    exit()
  if Ans[s]!=-1 and c!=Ans[s]:
    print(-1)
    exit()
  Ans[s]=c

Count=''
for j in range(len(Ans)):
  if Ans[j]==-1:
    Ans[j]=0
  Count+=str(Ans[j])

print(int(Count))
