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

ans = [0]*N
exist = 0

for i in range(1, M+1):
    s, c = map(int, input().split())
    if s > N:
        exist = -1
    elif ans[s-1] != c and ans[s-1] != 0:
        exist = -1
    else:
        ans[s-1] = c



if exist == -1 or ans[-N] == 0:
    print(-1)
else:
    ans_str = [str(n) for n in ans]
    print(int("".join(ans_str)))