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

    S = []
    C = []
    for i in range(M):
        pp, ss = map(str, input().split())
        S.append(pp)
        C.append(ss)

    ans = ['0'] * N

    for i in range(M):
        ans[int(S[i]) - 1] = C[i]

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

    print(-1)


resolve()