#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define re register
const int INF = 0x3f3f3f3f;
using namespace std;
int n, m;
ll a[1000005], dp[2][1000005];
int main(){
freopen("white_lies.in", "r", stdin);
freopen("white_lies.out", "w", stdout);
while(cin >> m >> n){
for (int i = 1; i <= n; i++){
cin >> a[i];
}
for (int i = 0; i <= n; i++){
dp[0][i] = 0;
dp[1][i] = 0;
}
for (int i = 1, k = 1; i <= m; i++, k ^= 1){
dp[k][i - 1] = -INF;
ll maxl = -INF;
for (int j = i; j <= n - m + i; j++){
maxl = max(maxl, dp[k ^ 1][j - 1]);
dp[k][j] = max(maxl, dp[k][j - 1]) + a[j];
}
}
ll ans = -INF;
for (int i = m; i <= n; i++){
ans = max(ans, dp[m&1][i]);
}
printf("%lld\n", ans);
}
return 0;
}