from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
#import math

#N=int(input())
#X,Y=map(int,input().split())
#S=list(map(int,input().split()))
#S=[list(map(int,input().split())) for i in range(N)]



N,M=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(M)]
dic={}
for s,c in sc:
    if not s in dic:
        dic.update({s:c})
    else:
        if dic[s]!=c:
            print(-1)
            exit()

data=""
for i in range(1,N+1):
    if i in dic:    
        if not data and dic[i]==0:
            print(-1)
            exit()

    if i in dic:


        if dic[i]!=0 or i==N:
            data+=str(dic[i])
    else:
        if data:
            data+="0"
if data:
    print(data)
else:
    print(-1)
#print(Counter(sc))
