N,M = map(int, input().split())
ans = [-1 for i in range (N)]
exist = True
for i in range(M):
    s,c = map(int, input().split())
    if ans[s-1] == -1:
        ans[s-1] = c
    else:
        if ans[s-1] != c:
            exist = False
            break

if ans[0] == 0:
    exist = False
elif ans[0] == -1:
    ans[0] = 1

if exist:
    ans = [0 if i == -1 else i for i in ans]
    print(''.join([str(i) for i in ans]))
else:
    print(-1)