import sys
n,m = map(int,input().split(" "))
nums = [0] * n
for _ in range(m):
    s,c = map(int,input().split(" "))
    if s == 1 and c == 0:
        print(-1)
        sys.exit(0)
    if nums[s-1] != 0 and c != nums[s-1]:
        print(-1)
        sys.exit(0)
    nums[s-1] = c
if n == 1:
    print(nums[0])
    sys.exit(0)
if nums[0] == 0:
    nums[0] = 1
print("".join(map(str,nums)))