n,m = map(int,input().split())
a=[]
s=[]
c=[]
ans=0
for i in range(n):
  a.append(0)
for j in range(m):
  s,c= map(int,input().split())
  if s==1 and c==0:
    ans=-1
  if a[s-1]==0 or a[s-1]==c:
    #print(str(j)+"e")
    a[s-1]=c
  else:
    ans=-1
if a[0]==0:
  a[0]=1
if ans!=-1:
  ans=0
  for k in range(n):
    ans+=a[k]*(10**(n-1-k))
print(ans)