def solve():
    N, M = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(M)]

    ans = 10000
    for i in range(1, 1000):
        c = 0
        for a, b in A:
            s = str(i)
            if len(s) >= a and s[a-1] == str(b):
                c += 1
        if c == M:
            ans = min(ans, i)
    
    if ans == 10000:
        ans = -1
        
    return ans

print(solve())