#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int fir = 1000, sec = 1000, thr = 1000;
  if (n == 1) {
    cout << a[0];
  } else {
    for (int i = 0; i < n; i++) {
      if (a[i] < fir) {
        thr = sec;
        sec = fir;
        fir = a[i];
      } else {
        if (a[i] < sec) {
          thr = sec;
          sec = a[i];
        } else {
          if (a[i] < thr) thr = a[i];
        }
      }
    }
    cout << fir + sec + thr;
  }
  return 0;
}
