n, m = map(int, input().split())
lst = []
for _ in range(m):
    s, c = map(int, input().split())
    lst.append([s-1,c])

ans = []
for _ in range(10**(n)-1):
    i = 1
    nums = list(str(_))
    while len(nums) < n:
        nums.insert(0,[])
    for s in lst:
        if nums[s[0]] != s[1]:
            i = 0
            break
        if i:
            ans.append(_)
if ans:
    print(min(ans))
else:
    print(-1)