N, M = map(int, input().split())
lists = [list(map(int, input().split())) for i in range(M)]

number = [0, 0, 0, 0, 0]
ss = {i:int(10) for i in range(10)}

for i in lists:
    if i[1] < ss[i[0]]:
        ss[i[0]] = i[1]
# print(ss)

for i in lists:
    number[i[0]+1] = ss[i[0]]

ans = number[N-1:]
ans = "".join(map(str, ans))
ans = int(ans)
ans = str(ans)

if len(ans) == N:
    print(ans)
else:
    print("-1")