#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (auto &x : v) cin >> x;
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    if (v[n] < 1e4) {
      sum += v[n];
      break;
    }
    if (v[i] < v[i + 1]) sum += v[i];
  }
  cout << sum;
  return 0;
}
