N, M = map(int, input().split())
sc = [list(input().split()) for _ in range(M)]

ans = '999'
st = {1, 2, 3}

for i in sc:
    s = i[0]
    c = i[1]
    a = ans[int(s) - 1]

    if c < a:
        la = list(ans)
        la[int(s) - 1:int(s)] = c
        ans = ''.join(la)
        st.remove(int(s))

for i in st:
    la = list(ans)
    la[i - 1:i] = '0'
    ans = ''.join(la)

if ans[0] == '0':
    print(-1)
else:
    print(ans)