#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, N, p;
  cin >> N >> K;
  vector<int> vec;
  for (int i = 0; i < N; i++) {
    cin >> p;
    vec.push_back(p);
  }
  sort(vec.begin(), vec.end());
  int loop = 0, ans = 0;
  if (vec.size() >= 3) {
    loop = 3;
  } else {
    loop = vec.size();
  }
  for (int j = 0; j < loop; j++) {
    ans += vec[j];
  }
  cout << ans << endl;
}
