N,M = map(int,input().split())
d = [-1 for _ in range(N)]
for _ in range(M):
    s,c = map(int,input().split())
    if d[s-1] == -1:
        d[s-1] = c
    else:
        if d[s-1]>c:
            d[s-1] = c
            
e = []
for i in d:
    if i == -1:
        e.append(0)
    else:
        e.append(i)
if N==0:
    print("".join(map(str,e)))
else:
    if e[0] == 0:
        print("-1")
    else:
        print("".join(map(str,e)))