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)]

    for k in range(1000):
        dec = '{0:03}'.format(k)
        for s, c in Conds:
            if dec[s - 1] != str(c):
                break
        else:
            if dec == '000':
                used = sorted([int(i) for i, j in Conds if j == 0])
                if used == [1]:
                    return -1
                elif used == [2]:
                    return 100
                elif used == [3]:
                    return 10
                elif used == [1, 2]:
                    return -1
                elif used == [2, 3]:
                    return 100
                elif used == [1, 2, 3]:
                    return -1
            return k
    return -1

print(c_guess_the_number())