n, m = map(int, input().split())
num = [" " for x in range(n)]
ans = 0

for i in range(m):
    s, c = map(int, input().split())
    c = str(c)
    
    if num[s - 1] == " " :
        num[s - 1] = c
    
    elif num[s - 1] == c :
        continue
    
    else:
        ans = -1
        break
        
if ans == -1 :
    print(-1)
else:
    num = "".join(num)
    ans = num.replace(" ", "0")
    print(int(ans))