n,m=map(int, input().split())
d = {}
flag = True
for _ in range(m):
    s, c = input().split()
    if d.get(s):
        if d.get(s) == c:
            continue
        else:
            flag = False
            break
    else:
        d[s] = c
if flag:
    if max(map(int, d.keys())) == n:
        l = ['0']*n
        for i in range(1,n+1):
            if d.get(str(i)):
                l[i-1] = d.get(str(i))
        print(''.join(l))
    else:
        print(-1)
else:
    print(-1)