#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int n, k, x, j = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  x = 0;
  for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
    j++;
    x += (*it);
    if (j == 3) {
      break;
    }
  }
  cout << x;
  return 0;
}
