import math


def get_data_size(data):
    """桁数を求める

    Args:
        data (int): 数値

    Returns:
        [int]: 桁数

    Examples:
        >>> get_data_size(12541)
        5
    """
    return int(math.log10(data) + 1)


def resolve():
    N, M = map(int, input().split())

    checked = [False] * N
    ans = ['0'] * N

    for i in range(M):
        ss, cc = input().split()
        index = int(ss) - 1

        if checked[index] and ans[index] != cc:
            print(-1)
            return

        ans[index] = cc
        checked[index] = True

    ans = int(''.join(ans))
    if ans > 0 and N == get_data_size(ans):
        print(ans)
        return

    if ans == 0 and N == 1:
        print(0)
        return

    print(-1)

resolve()