N, M = map(int, input().split())
num = [[] for y in range(N)]


for x in range(M):
    s, c = map(int, input().split())
    num[s-1].append(c)

if not len(num) == 1:
    while 0 in num[0]:
        num[0].remove(0)

    if not num[0] or not num[0]:
        print("-1")
        exit()

a = []
for n in num:
    if not n:
        a.append("0")
        continue
    a.append(str(min(n)))

print(int("".join(a)))