import numpy as np

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

number = [0, 0, 0, 0, 0]
# numbers = np.zeros(5)
# print(number)
# print(numbers)

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

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

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