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

ans_l = [0 for _ in range(N)]

ng = False

for _ in range(M):
    s, c = [int(x) for x in input().split(' ')]
    if ans_l[s-1] == 0 or ans_l[s-1] == c:
        ans_l[s-1] = c
    else:
        ng = True

if ans_l[0] == 0 and N != 1:
    ng = True

if ng:
    print(-1)
else:
    ans_l = [str(x) for x in ans_l]
    print(int(''.join(ans_l)))