#include <bits/stdc++.h>
using namespace std;
int n, k;
int p[1005];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
  }
  sort(p + 1, p + n + 1);
  cout << p[1] + p[2] + p[3] << '\n';
  return 0;
}
