N,M = map(int,input().split())
k = []
zyouken = [0]*M
flag = 0
ans = ""
for i in range(M):
    s,c = map(int,input().split())
    k.append([s,c])
k.sort()
for j in range(len(k)):
    if zyouken[k[j][0]-1] == 0:
        zyouken[k[j][0]-1] = k[j][1]
    else:
        if zyouken[k[j][0]-1] != k[j][1]:
            print(-1)
            flag += 1
            break
if flag == 0:
    if sum(zyouken) == 0:
        print(-1)
    else:
        for i in range(len(zyouken)):
            ans += str(zyouken[i])
print(ans)