N,M=map(int,input().split())
ans=[0]*(N)
ans[0]=1

if M==0 and N==1:
  print("0")
  exit()
elif M==0 and N!=1:
  answer=''
  for i in range(N):
    answer+=str(ans[i])
  print(answer)
  exit()

sc=[list(map(int,input().split())) for i in range(M)]
s=[]
c=[]

for i in range(M):
  s.append(sc[i][0]-1)
  c.append(sc[i][1])

S=[s[0]]
C=[c[0]]
for i in range(1,M):
  if s[i] in S:
    if C[S.index(s[i])]==c[i]:
      continue
    else:
      print('-1')
      exit()
  else:
    S.append(s[i])
    C.append(c[i])

for i in range(M):
  ans[s[i]]=c[i]

if len(ans)!=0 and ans[0]==0:
  print('-1')
  exit()

ANS=""
for i in range(N):
  ANS+=str(ans[i])
print(ANS)