// const { xcode } = require("react-syntax-highlighter/dist/esm/styles/hljs");
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
// 读取输入
let M = parseInt(await readline());
let P = (await readline()).split(" ").map(Number);
// dp[i]表示预算为i时能获得的最大短信条数
let dp = new Array(M + 1).fill(0);
// 对每个预算金额i
for (let i = 1; i <= M; i++) {
// 尝试每种充值方案j
for (let j = 1; j <= P.length && j <= i; j++) {
dp[i] = Math.max(dp[i], dp[i - j] + P[j - 1]);
}
}
console.log(dp[M]);
})();