INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,m=INTM()
    ss=[]
    cs=[]
    temp=[10]*n
    flg=0
    for i in range(m):
        s,c=INTM()
        ss.append(s)
        cs.append(c)
        if s==1 and c==0:
            flg=1
            
    #print(temp)
    #print(ss)
    #print(cs)
    
    for i in range(m):
        if temp[ss[i]-1]==10:
            temp[ss[i]-1]=cs[i]
        else:
            if temp[ss[i]-1]!=cs[i]:
                flg=1
    for i in range(n):
        if temp[i]==10:
            temp[i]=0
    ans=''
    for i in temp:
        ans+=str(i)
    if flg ==1:
        print(-1)
    else:
        print(ans)
    
    
if __name__ == '__main__':
    do()