#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  priority_queue<int, vector<int>, greater<int>> pq;
  for (int i = 0; i < n; ++i) {
    int p;
    pq.push(p);
  }
  int cost = 0;
  while (k > 0) {
    cost += pq.top();
    pq.pop();
    k--;
  }
  cout << cost << endl;
}
