a, b = map(int, input().split())
list_num=[-1]*a
point=0
for i in range(b):
    s, c = map(int, input().split())
    if a<s: 
        point=1
    elif list_num[s-1]==-1:
        list_num[s-1]=c
    elif list_num[s-1]==c:
        pass
    else:
        point=1
if a==3:
    sum1=list_num[2]+(list_num[1]*10)+(list_num[0]*100)
elif a==2:
    sum1=list_num[1]+(list_num[0]*10)
else:
    sum1=list_num[0]
if point==1:
    print(-1)
elif -1 in list_num:
    print(-1)
else:
    print(sum1)