def c_guess_the_number():
    N, M = [int(i) for i in input().split()]
    Conds = [[int(i) for i in input().split()] for j in range(M)]

    digit = [-1] * N
    ans = [0] * N
    for s, c in Conds:
        d = s - 1
        if digit[d] != -1 and digit[d] != c:
            return -1
        ans[d] = c
        digit[d] = c
    ans2 = int(''.join(map(str, ans)))
    if len(str(ans2)) != N:
        return -1
    return ans2

print(c_guess_the_number())