n, m = map(int, input().split())
nums = [99] * n

for _ in range(m):
    n1, n2 = map(int, input().split())
    nums[n1-1] = min(nums[n1-1], n2)

if nums[0] != 0:
    if nums[0] == 99:
        nums[0] = 1
    print("".join([str(x) if 0<=x and x<=9 else "0" for x in nums]))
else:
    print(-1)