#include <bits/stdc++.h>
using namespace std;
int n, k, num[100005];
long long ans, cc, ss1, ss2, sg;
int main() {
  int n;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
    ans += num[i];
    if (i > n - k) ss1 += num[i];
  }
  cc = 0;
  for (int i = 1; i <= n - k; i++) {
    if (num[i] > 0) cc += num[i];
  }
  bool p = true;
  for (int i = n - k + 1; i <= n; i++) {
    if (p) {
      if (num[i] > 0)
        ss2 += num[i];
      else
        p = false;
    }
  }
  cc += max(ss2, ss1);
  for (int i = 1; i <= n - k; i++) {
    if (num[i] < 0) sg += num[i];
  }
  p = true;
  ss2 = 0;
  for (int i = n - k + 1; i <= n; i++) {
    if (p) {
      if (num[i] < 0)
        ss2 += num[i];
      else
        p = false;
    }
  }
  sg += min(ss1, ss2);
  printf("%lld", max(ans - sg, cc));
}
