n,m=map(int,input().split())
sc=[[0]*2 for ii in range(m)]
for ii in range(m):
  sc[ii][:]=map(int,input().split())
s=[0]*n
f=[False]*n
for ii in range(m):
  if f[sc[ii][0]-1]:
    if s[sc[ii][0]-1]!=sc[ii][1]:
      print(-1)
      exit()
  else:
    f[sc[ii][0]-1]=True
    s[sc[ii][0]-1]=sc[ii][1]
    
if n>1 and s[0]==0:
  print(-1)
  exit()
print(int("".join([str(ii) for ii in s])))