n,m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
for i in range(1000):
    for j,k in sc:
        if len(str(i)) < j or len(str(i)) != n:
            break
        elif  int(str(i)[j-1]) != k:
            break

    else:
        print(i)
        break
else:
    print(-1)