#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <functional>
using namespace std;

class MulticoreProcessing {
public:
	long long fastestTime(long long N, int M, vector <int> speed, vector <int> cores) {
		long long ret = (1LL << 60), MM = M;
		for (int i = 0; i < speed.size(); i++) {
			long long L = 1, R = (1LL << 30), U, maxn = 0;
			for (int j = 0; j < 34; j++) {
				U = (L + R) / 2;
				if ((N / (U*(U + 1))) < MM) { R = U; }
				else { L = U; maxn = max(maxn, U); }
			}
			long long I = min(1LL * cores[i], max(1LL, U));
			long long J = ((N - 1) / (1LL * speed[i] * I)) + 1LL; J += (I - 1)*MM;
			ret = min(ret, J);
		}
		return ret;
	}
};