def main():
    digits, m = [int(x) for x in input().split()]
    orders = []
    for _ in range(m):
        left_count, numeral = [int(x) for x in input().split()]
        left_count -= 1
        orders.append((left_count, numeral))

    def gen():
        for x in range(10 ** digits):
            if x < 10 ** (digits - 1):
                continue
            ok = True
            s = str(x)
            for left_count, numeral in orders:
                if len(s) <= left_count:
                    ok = False
                    break
                if s[left_count] != str(numeral):
                    ok = False
                    break
            if ok:
                yield x

    candidates = gen()
    try:
        print(min(candidates))
    except ValueError:
        print(-1)
    return


if __name__ == '__main__':
    main()
