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

s = []
c = []

ans = [0] * N

Flag = True

for i in range(M):
    S, C = list(map(int, input().split()))
    if ans[S-1] == 0:
        ans[S-1] = C
    else:
        if ans[S-1] != C:
            Flag = False
            break

if ans[0] == 0:
    Flag = False

if Flag:
    print(*ans, sep='')
else:
    print(-1)