n, m = map(int, input().split())
nums = {}
ans = 10**(n-1)

for _ in range(m):
    s, c = map(int, input().split())
    if not s in nums.keys():
        nums[s] = c
    elif s in nums.keys():
        if nums[s] != c:
            ans = -1
            break
        else:
            continue
        
    if s == 1:
        if c == 0:
            ans = -1
            break
        else:
            ans *= c
    else:
        ans += c * 10**(n-s)

print(ans)