
n, m = map(int, input().split())

num = [0] * n
for i in range(m):
    s, c = map(int, input().split())
    if num[s - 1] == 0:
        num[s - 1] = c
    else:
        num[s - 1] = min(num[s - 1], c)
    
if num[0] == 0:
    print(-1)
else:
    for i in range(n):
        print(num[i], end="")