n, m = map(int, input().split())
num = [-1] * n
info = []
answer = ''
for _ in range(m):
    info.append(tuple(map(int, input().split())))
info.sort()
# print(num, info)

for si, ci in info:
    if num[si-1] == -1:
        num[si-1] = ci
    if num[si-1] > ci:
        num[si-1] = ci

# print(num)
if num[0] == -1 or (n == 3 and num[0] == 0) or (n == 2 and num[0] == 0) or m == 0:
    print(-1)
    exit()

for n in num:
    if n == -1:
        answer += '0'
    else:
        answer += str(n)

print(answer)