N, M = map(int, input().split())
s = [0]*M
c = [0]*M
for i in range(M):
    s[i], c[i] = map(int, input().split())
result = 0

dic = dict(zip(s, c))
result = [0, 0, 0]
for i in range(3):
    if len(set([c[s == i+1]]))>=2:
        result = -1
    elif (s[i]==1)*(c[i]==0):
        result = -1
    else:
        if i+1 in dic:
            result[i] = dic[i+1]
        else:
            pass
results = ''       
if len(result)>1:
    for i in result:
        results += str(i)
    print(int(results))
else:
    print(result)