n, m = map(int, input().split())
nums = {}
ans = 0
for _ in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        ans = -1
        break

    if not s in nums.keys():
        nums[s] = c
        ans += c * 10**(n-s)
    elif c != nums[s]:
        ans = -1
        break
    
print(ans)