def create_num(sc, N):
    M = len(sc)
    num_list = [None for i in range(N)]

    ## N桁目を表す数字配列を作成
    for i in range(M):
        ## 既に異なる数字が入っている場合はだめ、1桁目が0もだめ
        if (num_list[sc[i][0]-1]==sc[i][1] or num_list[sc[i][0]-1] is None)\
                and not((sc[i][0] == 1 and sc[i][1] == 0) if N > 1 else False):
            num_list[sc[i][0]-1] = sc[i][1]
        else:
            return -1

    ## 最小の数字になる配列を作成
    if num_list[0] is None and N > 1: num_list[0] = 1
    for i in range(N-1):
        if num_list[i+1] is None: num_list[i+1] = 0

    return create_num_from_list(num_list)


def create_num_from_list(num_list):
    n = 0
    num_list.reverse()
    for i, num in enumerate(num_list):
        n += num*(10**i)
    return n


def resolve():

    N, M = map(int, input().split())
    sc = []
    for i in range(M):
        sc += [list(map(int, input().split()))]
    print(create_num(sc, N))
    
resolve()