n, m = map(int, input().split())
digit_dict = {i+1: set() for i in range(n)}
result = ''
for i in range(m):
    s, c = map(int, input().split())
    digit_dict[s].add(c)
if digit_dict[1] == {0} and n >= 2:
    print(-1)
elif [i for i in digit_dict.values() if len(i)>=2]:
    print(-1)
else:
    if digit_dict[1]:
        for key, value in sorted(digit_dict.items(), key=lambda x: x[0]):
            if not value:
                result += '0'
            else:
                result += str(*value)
        print(result)
    else:
        print(-1)
        
        
        