N, M = map(int, input().split())
num = [0 for i in range(N)]

for i in range(M):
    s, c = map(int, input().split())
    if num[s-1] == 0 or num[s-1] == c:
        num[s-1] = c
    else:
        print(-1)
        exit()

if num[0] == 0:
    print(-1)
    exit()
else:
    for j in range(N):
        print(num[j], end="")
