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 num[0] or num[0] == [0]:
    print("-1")
    exit()

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

print("".join(a))



