#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  if (n >= 3) {
    cout << a[0] + a[1] + a[2] << endl;
  } else if (n = 2) {
    cout << a[0] + a[1] << endl;
  } else
    cout << a[0] << endl;
}
