N, M = list(map(int, input().split()))
ans = [-1]*N

flag = True
for _ in range(M):
    s, c = list(map(int, input().split()))
    if s == 1 and c == 0:
        flag = False
        break
    
    if ans[s-1] == -1:
        ans[s-1] = c
    else:
        if ans[s-1] != c:
            flag = False
            break

if flag:
    print("".join(["3" if e == -1 else str(e) for e in ans]))
else:
    print(-1)
