n, m = map(int, input().split())
nums = {1:None, 2:None, 3:None}
ans = 0
 
for _ in range(m):
    s, c = map(int, input().split())
    if nums[s] == None:
        nums[s] = c
    else:
        if nums[s] != c:
            ans = -1
            break
        else:
            continue

if n == 1 and m == 0:
    print(0)
elif ans == -1:
    pass
else:
    for k, v in nums.items():
        if v == None:
            nums[k] = 0
        elif k == 1 and v == 0:
            ans = -1
            break
    if ans != -1:
        for number in range([0, 10, 100][n-1], 10**n):
            number = str(number)
            if all(int(i)==int(j) for i, j in zip(nums.values(), number)):
                asn = number
                break
            else:
                continue

print(ans)