N,M = map(int,input().split())
lis = [list(map(int,input().split())) for _ in range(M)]
d = [0]*N
for i in range(M):
    if d[lis[i][0]-1] != 0:
        if d[lis[i][0]-1]<=lis[i][1]:
            d[lis[i][0]-1] = lis[i][1]
    else:
        d[lis[i][0]-1] = lis[i][1]
if d[0]==0:
    print("-1")
else:
    print("".join(map(str,d)))