n, m = list(map(int, input().split()))
num = [-1] * n


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

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

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