n, m  = map(int,input().split())
D = {}
res = ["0"]*n
for i in range(m) :
    s,c = input().split()
    if s not in D :
        D[s] = c
    elif D[s] != c :
        print(-1)
        exit()

for s, c in D.items() :
    res[int(s)-1] = c

if res[0] == "0" :
    print(-1)
else :
    print("".join(res))
