const solution = (m, arr) => {
let min = Math.floor(arr.reduce((acc, cur) => acc + cur, 0) / m);
let sum = 0;
let result = 0;
for (let i = 0; i < arr.length; i++) {
if (sum + arr[i] >= min) {
result = sum + arr[i];
sum = 0;
}
sum += arr[i];
}
return result;
};