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

flag = True

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

else:
    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:
        ans[0] = max(1, ans[0])
        print("".join(["0" if e == -1 else str(e) for e in ans]))
    else:
        print(-1)
