


def iln(): return list(map(int, input().split()))

N, M = iln()

S, C = [], []
for i in range(M):
    s, c = iln()
    S.append(s)
    C.append(c)

def solve():
    target_num = [0] * N
    for i in range(M):
        target_num[S[i] - 1] = C[i]

    if target_num[0] == 0 and N > 1:
        return None
    return target_num

target_num = solve()
if target_num is None:
    print(-1)
else:
    total = 0
    pos_value = 10 ** (N - 1)
    for i in range(N):
        if target_num[i] > 0:
            total += target_num[i] * pos_value
        pos_value //= 10
    
    print(total)
