N, M = map(int, input().split(' '))

S = ['0', None, None, None]

for _ in range(M):
    s, c = map(int, input().split(' '))
    if S[s] is None:
        S[s] = str(c)
    elif S[s] != str(c):
        print(-1)
        break
else:
    if S[-N] is None:
        S[-N] = '1'
    for i in range(len(S)):
        if S[i] is None:
            S[i] = '0'

    if S[-1] == '0':
        print(-1)
    else:
        print(int(''.join(S)))
