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

num = [-1] * n

for _ in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and n > 1:
        print(-1)
        exit()
    if num[s-1] == -1 or num[s-1] == c:
        num[s-1] = c
    else:
        print(-1)
        exit()

for i in range(n):
    if num[i] == -1:
        num[i] = 0

print(''.join(map(str, num)))

