# C - Guess The Number
def guess_number(N: int, M: int, conditions: list) -> int:
    if N == 1:
        digit, num = conditions[0]
        if len(set(conditions)) == 1 and digit == 1:
            return num
        return -1

    if any(cond == (1, 0) for cond in conditions):  # 1st digit mustn't be 0
        return -1

    result = [0] * N
    for digit, num in conditions:
        if result[-digit] not in (0, num):
            return -1
        result[-digit] = num
    return sum(x * (10 ** i) for i, x in enumerate(result))


def main():
    N, M, *SC = map(int, open(0).read().split())
    conditions = list(zip(*[iter(SC)] * 2))
    ans = guess_number(N, M, conditions)
    print(ans)


if __name__ == "__main__":
    main()
