n,m = map(int,input().split())

ln = 10**10
a = [ln for _ in range(n)]
flag=0
for _ in range(m):
  index, val = map(int,input().split())
  if index-1 ==0 and val==0:
    print(-1)
    flag=1
    break
  if a[index-1]> val:
    a[index-1]=val

for i in range(n):
  if a[i] == ln:
    a[i]=0
if flag==0:
  if a[0]==0:
    print("-1")  
  else:
    for i in a:
      print(i,end="")