n,m = map(int,input().split())
ans = [0]*n
for i in range(n):
    s,c = map(int,input().split())
    if ans[s-1] == 0 or ans[s-1] == c:
        ans[s-1] = c
    else:
        print(-1)
        exit()
if ans[0] == 0:
    print(-1)
    exit()
print("".join([str(n) for n in ans]))