N, M = map(int, input().split())

ans = [None] * 4

for _ in range(M):
    s, c = map(int, input().split())
    if ans[s] == None:
        ans[s] = c
    elif ans[s] != c:
        print(-1)
        exit()

if ans[1] == None or ans[1] == 0:
    print(-1)
    exit()

for i in range(1, 4):
    if ans[i] == None:
        ans[i] = 0

print(ans[1] * 100 + ans[2] * 10 + ans[3])