n,m = (int(num) for num in input().split())
ans = ["empty"] * n
isPossible = True
for _ in range(m):
    s,c = (int(num) for num in input().split())
    idx = s - 1
    if ans[idx] == "empty" or ans[idx] == c:
        ans[idx] = c
    else:
        isPossible = False
if n != 0 and ans[0] == 0:
    isPossible = False
    
ans_str = ""
    
if isPossible:
    for i in range(len(ans)):
        num = ans[i]
        if num == "empty":
            if i == 0:
                ans_str += "1"
            else:
                ans_str += "0"
        else:
            ans_str += str(num)
else:
    ans_str = "-1"
    
print(ans_str)