N,M = list(map(int, input().split()))
flag = []
ans = []
for i in range(N):
  flag.append(0)
  ans.append(0)
minusflag = 0
for i in range(M):
  s,c = list(map(int, input().split()))
  if(flag[s-1]==0):
    ans[s-1] = c
    flag[s-1] = 1
  elif(flag[s-1]==1 and ans[s-1]==c):
    flag[s-1] = 1
  else:
    minusflag = 1
    break
strans = ""
for i in range(N):
  strans += str(ans[i])
if(N!=1 and (minusflag==1 or ans[0]==0) ):
  print(-1)
elif(N==1):
  if(minusflag==1):
    print(-1)
  else:
    print(strans)
else:
  print(strans)