def solve():
    N, M = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(M)]
    
    ans = 10 ** 5
    for i in range(1000):
        s = str(i)
        c = 0
        for a, b in A:
            if len(s) > a-1 and int(s[a-1]) == b:
                c += 1

        if c == N:
            ans = min(i, ans)
    
    if ans == 10 ** 5:
        ans = -1
    
    return ans

print(solve())