#include <cstdio> #include <algorithm> #define FI(a, b, c) for(int a = (b); a <= (c); a++) #define FD(a, b, c) for(int a = (b); a >= (c); a--) using namespace std; int n, m, t; long long d[1005], l[1005]; int main(){ while(scanf("%d %d", &m, &n) != EOF){ FI(i, 1, m) d[i] = l[i] = -1e15; while(n--){ scanf("%d", &t); FD(i, m, 1){ d[i] = max(d[i], l[i - 1]) + t; l[i] = max(l[i], d[i]); } } printf("%d ", l[m]); } }