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 N == 3:
    if num1 == '0':num1 = ''
    if num2 == '':num2 ='0'
    if num3 == '':num3 ='0'
elif N == 2:
    if num1 == '0':num1 = ''
    if num2 == '0':num2 = ''
    if num3 == '':num3 ='0'
else:
    if num1 == '0':num1 = ''
    if num2 == '0':num2 = ''
    if num3 == '':num3 ='0'
ans = num1+num2+num3

if len(ans) == N:
    print(ans)
else:print('-1')