N, M = map(int, input().split())
s = [0] * N
for i in range(M):
    digit, num = map(int, input().split())
    digit -= 1
    if digit == 0 and num == 0 and N != 1:
        print(-1)
        exit()
    if s[digit] != 0 and s[digit] != num:
        print(-1)
        exit()
    s[digit] = num
print(''.join(map(str, s)))