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

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