n, m = map(int, input().split())
lst = [[] for _ in range(n)]
for _ in range(m):
    s, c = map(int, input().split())
    lst[s-1].append(c)
    
def has_duplicates(seq):
    return len(seq) != len(set(seq))
i = 0
ans= 0
for _ in lst:
    if has_duplicates(_) and len(set(_)) >1:
        i = -1
        
if n > 1 and len(set(lst[0])) == 1 and 0 in lst[0]:
        i = -1
if i != -1:
    for _ in range(n):
        if _ == 0:
            lst[_].append(1)
        else:
            lst[_].append(0)
        ans += max(lst[_]) * 10 ** (n -(_+1))
    print(ans)
else:
    print(i)
