n,m=map(int, input().split())
l = ['0']*n
for _ in range(m):
    s, c = input().split()
    index = int(s)-1
    if l[index] == '0':
        l[index] = c
    else:
        if int(c) < int(l[index]):
            l[index] = c
if l[0] == '0':
    print(-1)
else:
    print(''.join(l))