n = list(map(int,input().split()))
strlist=[input() for i in range(n[1])]
for i in range(10**(n[0]-1),10**n[0]):
    for j in range(n[1]):
        if len(str(i))<int(strlist[j][0]) or str(i)[int(strlist[j][0])-1]!=strlist[j][2]:
            z=1
            break
    if z==1:
        continue
    elif j+1==n[1]:
        print(i)
        break
    else:
        continue
if i==10**n[0]-1:
    print('-1')