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)):
    i = 1
    nums = list(str(_))
    while len(nums) < n:
        nums.insert(0,'0')
    for s in lst:
        if nums[s[0]] != str(s[1]):  
            i = 0
            break
    if n > 1 and nums[3-(n+1)] == '0':
        pass
    elif i == 1:
        ans.append(_)

if ans:
    print(min(ans))
else:
    print(-1)
