def main():
    n, m = [int(i) for i in input().split()]
    # digits = [(int(i) for i in input().split()) for _ in range(m)]
    digits = [-1] * n
    for i in range(m):
        s, c = [int(i) for i in input().split()]
        if not digits[s-1] in (-1, c):
            print(-1)
            return

        digits[s-1] = c

    top = True
    for i in range(n):
        d = digits[i]
        if top:
            if d == 0:
                if i+1 < n:
                    print(-1)
                    return
            if d == -1:
                digits[i] = 0
            else:
                top = False
        else:
            if d == -1:
                digits[i] = 0

    t = str(int("".join([str(i) for i in digits])))
    print(t if len(t) == n else -1)

main()
