N,M = map(int,input().split())
sc = {}
flag = False
smax = 0
for i in range(M):
    s,c = map(int,input().split())
    smax = max(s,smax)
    if s > N:
        flag = True
        break
    elif s not in sc:
        sc[s] = c
    else:
        if sc[s] != c:
            flag = True
            break
if flag:
    print(-1)
else:
    ans = [0 for i in range(smax)]
    for s,c in sc.items():
        ans[s-1] = c
    if ans[0] == 0:
        print(-1)
    else:
        print(*ans,sep='')