N, M = map(int, input().split())
S = [input().split() for _ in [0]*M]

for i in range(1000):
    if len(str(i)) != N:
        continue
    for s, c in S:
        if str(i)[int(s)-1] == c:
            continue
        else:
            break
    else:
        print(i)
        break
else:
    print(-1)
