import sys

N,M=map(int,input().split())
l = list()
num1=str('')
num2=str('')
num3=str('')

for _ in range(M):
    l.append(input().split())
l.sort()
for i in l:
    keta_num = i[0]
    if keta_num == '1':
        if num1 == '':
            num1 = i[1]
        else:
            if num1 != i[1]:
                print('-1')
                sys.exit()
    elif keta_num == '2':
        if num2 == '':
            num2 = i[1]
        else:
            if num2 != i[1]:
                print('-1')
                sys.exit()
    else:
        if num3 == '':
            num3 = i[1]
        else:
            if num3 != i[1]:
                print('-1')
                sys.exit()
if num1 == '':num1='0'
if num2 == '':num2='0'
if num3 == '':num3='0'
ans = str('')
if num1!=0:
    ans=num1+num2+num3
elif num2!=0:
    ans=num2+num3
else:ans=num3
if len(ans) == N:
    print(ans)
else:print('-1')