import sys
import math
N, M = map(int, input().split())
NUMS = [list(map(int, input().split())) for _ in range(M)]

for n in range(10 ** (N - 1), 10 ** (N)):
    res = 0
    for s, c in NUMS:
        if str(n)[s - 1] == str(c):
            res += 1
    
    if res == M:
        print(n)
        sys.exit()
        
print("-1")