N, M = map(int, input().split())

S = ["0" for i in range(N)]

dic = {}

flag = True

#print(S)

for _ in range(M):
    s, c = map(int, input().split())

    if s in dic:
        if dic[s] > c:
            dic[s] = c
            S[s - 1] = str(c)
    else:
        dic[s] = c
        S[s - 1] = str(c)

#print(S)

# 0かどうかをチェック
if N != 1 and S[0] == "0":
    flag = False
#print(int("".join(S)))

print(int("".join(S))) if flag else print(-1)