N,M=list(map(lambda i:int(i),input().split()))
dict={}
exist=True

def getLeast(digit):
    if digit in dict.keys():
        return  dict[digit]
    else:
        return 0

if M==0:
    if N==3:
        print(100)
        exit()
    elif N==2:
        print(10)
        exit()
    elif N==1:
        print(0)
        exit()

#重複チェック
for i in range(M):
    s,c=list(map(lambda i:int(i),input().split()))
    if s in dict.keys() and c != dict[s]:
        exist=False
        break
    else:
        dict[s]=c

#桁チェック
if exist==True:
    if 1 in dict.keys():
        if N==3 and dict[1]==0:
            exist=False
        elif N==2 and dict[1]!=0:
            exist=False
        elif N==1 and dict[1]!=0:
            exist = False
    if 2 in dict.keys():
        if N==2 and dict[2]==0:
            exist = False
        elif N==1 and dict[2]!=0:
            exist = False

if exist==False:
    print("-1")
else:
    if N==3:
        if 1 in dict.keys():
            answer= dict[1]*100+getLeast(2)*10+getLeast(3)
        else:
            answer=100+getLeast(2)*10+getLeast(3)
        print(answer)
    elif N==2:
        if 2 in dict.keys():
            answer= dict[2]*10 +getLeast(3)
        else:
            answer=10++getLeast(3)
        print(answer)
    elif N==1:
        answer=getLeast(3)
        print(answer)
