import std.algorithm, std.range;
import std.string;
import std.conv;
import std.stdio;
void main()
{
    readln.chomp.split[1].to!long.solve(
            readln.chomp.split.to!(long[]),
            readln.chomp.split.to!(long[])).writeln;
}
private:
auto solve(long maxTraining, long[] currentCost, long[] difficulty)
{
    long training(long timelimit)
    {
        if (timelimit < 0)
            return long.max;
        return currentCost.minTraining(difficulty.maxCost(timelimit));
    }
    long minExcTimelimit = -1, maxIncTimelimit = 1_000000_000000;
    while (minExcTimelimit + 1 < maxIncTimelimit)
    {
        assert (maxTraining < training(minExcTimelimit));
        assert (training(maxIncTimelimit) <= maxTraining);
        immutable midTimelimit = minExcTimelimit + ((maxIncTimelimit - minExcTimelimit) >> 1);
        if (training(midTimelimit) <= maxTraining)
            maxIncTimelimit = midTimelimit;
        else
            minExcTimelimit = midTimelimit;
    }
    return maxIncTimelimit;
}
unittest
{
    assert (solve(5, [long(4), 2, 1], [long(2), 3, 1]) == 2);
    assert (solve(8, [long(4), 2, 1], [long(2), 3, 1]) == 0);
    assert (solve(14,
            [long(3), 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],
            [long(8), 9, 7, 9, 3, 2, 3, 8, 4, 6, 2]) == 12);
}
long[] maxCost(long[] difficulty, long timelimit)
{
    auto ret = new long[difficulty.length];
    ret[] = timelimit / difficulty[];
    return ret;
}
unittest
{
    assert ([long(2), 3, 1].maxCost(2) == [1, 0, 2]);
}
long minTraining(long[] currentCost, long[] maxCost)
{
    return long(0).reduce!((a, b) => a + 0.max(b[0]-b[1]))
    (
        currentCost.sort!"a>b".zip
        (maxCost.sort!"a>b")
    );
}
unittest
{
    assert ([long(4), 2, 1].minTraining([1, 0, 2]) == 4);
}
unittest
{
    stderr.writeln("unittest passed!");
}
