n, m = map(int, input().split())
nums = [0] * n
flgs = [0] * n
cnt = 0
for _ in range(m):
    s, c = map(int, input().split())
    if flgs[s-1] == 0:
        nums[s-1] = c
        cnt += 1
        flgs[s-1] = 1
    elif flgs[s-1] != 0:
        if nums[s-1] == c:
            cnt += 1
            continue
        else:
            break
ans = ""
for num in nums:
    ans += str(num)
if cnt == m and nums[0] != 0:
    print(ans)
else:
    print("-1")
