N, M = map(int,input().split())
ans = -1
if N == 1:
    kazu = list(range(10))
elif N == 2:
    kazu = list(range(10,100,1))
else:
    kazu = list(range(100,1000,1))

#print(kazu)
neikazu = kazu

for j in range(M):
    s, c = map(int,input().split())
    print(s,c)
    for i in range(1000):
        if i not in kazu:
            pass
        else:
            if N + 1 - s == 1:
                if i % 10 != c:
                    kazu.remove(i)
                    #print('KKK')
            elif N + 1 - s == 2:
                if (i % 100) //10 != c:
                    kazu.remove(i)
                    #print('JJJ')
            else:
                if i // 100 != c:
                    kazu.remove(i)
                    #print('HHH')
if len(kazu) == 0:
    pass
else:
    ans = kazu[0]


print(ans)


    

