N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

arr = [-1] * (N + 1)

for s, c in SC:
    if arr[s] != -1 and arr[s] != c:
        print(-1)
        exit()
    else:
        arr[s] = c

answer = 0
for i in range(1, N + 1):
    if i == 1:
        if arr[i] == 0:
            print(-1)
            exit()
        else:
            if arr[i] != -1:
                answer = answer * 10 + arr[i]
            else:
                answer = answer * 10 + 0
    else:
        if arr[i] != -1:
            answer = answer * 10 + arr[i]
        else:
            answer = answer * 10 + 0
            
print(answer)