N, M = [int(x) for x in input().split()]

cond = [None for _ in range(N + 1)]
ok = True
for i in range(M):
    s, c = [int(x) for x in input().split()]
    if cond[s] == None:
        cond[s] = c
    else:
        if cond[s] != c:
            ok = False
            break

if cond[1] == 0:
    ok = False

if cond[1] == None:
    cond[1] = 1

if ok == True:
    for i in range(1, N + 1):
        if cond[i] == None:
            print(0, end='')
        else:
            print(cond[i], end='')
else:
    print(-1, end='')

print('')