if __name__ == '__main__':
    n, m = tuple([int(s) for s in input().split()])
    digits = [None] * 3
    failed = False

    for i in range(m):
        si, ci = tuple([int(s) for s in input().split()])

        if (si == 1 and ci == 0) or si > n:
            print(-1)
            failed = True
            break

        if digits[si - 1] is not None and digits[si - 1] != ci:
            print(-1)
            failed = True
            break
        else:
            digits[si - 1] = ci

    if not failed:
        i = 0

        while digits[i] is None and len(digits[i:]) > n:
            i += 1

        else:
            digits = digits[i:]
            if digits[0] is None:
                digits[0] = 1
            for j in range(len(digits)):
                if digits[j] is None:
                    digits[j] = 0

            print("".join(["{}".format(d) for d in digits]))
