n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
num=[-1]*n
rec=dict()
for i in range(m):
  if sc[i][0] in rec and str(sc[i][1])!=num[sc[i][0]-1]:
    print(-1)
    exit()
  else:
    rec[sc[i][0]]=0
    num[sc[i][0]-1]=str(sc[i][1])
if num[0]=='0':
  if n>1:
    print(-1)
    exit()
cntnot0=0
for i in range(n):
  if num[i]!=-1:
    cntnot0+=1
  if cntnot0==0:
    if num[i]==-1:
      print(-1)
      exit()
  else:
    if num[i]==-1:
      num[i]='0'
print(''.join(num))