for x in range(0, 1000):
    if not len(str(x)) == N:
        continue
    p = []
    for i, y in enumerate(num, start=0):
        if not y:
            y.append("0")
        try:
            p.append(str(x)[i] in y)
        except:
            continue
    if all(p):
        print(x)
        exit()

print(-1)