def solve():
    n, m = map(int, input().split())
    if m == 0:
        if n == 1:
            return 0
        else:
            return 10 ** (n-1)

    nums = [-1] * n
    for _ in range(m):
        s, c = map(int, input().split())
        if nums[s-1] != -1 and nums[s-1] != c:
            return -1
        else :
            nums[s-1] = c
    
    if nums[0] == 0:
        return -1
    
    start, end = 0, 10 ** (n)-1
    if n != 1:
        start = 10 ** (n-1)
        
    for v in range(start, end + 1):
        chk = True
        s = str(v)
        for i in range(n):
            if nums[i] == -1 or nums[i] == int(s[i]):
                continue
            chk = False
        if chk:
            return v
    return -1

print(solve())