#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[m], b[m];     int ndup = n;     for (int i = 0; i < m; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(a, a + m);     sort(b, b + m, greater<int>());     int mn = 0, mx = 0;     for (int i = 0; i < m; i++) {       while (a[i] > 0 && n > 0) {         mn += a[i];         a[i]--;         n--;       }     }     while (ndup > 0) {       mx += b[0];       b[0]--;       ndup--;       sort(b, b + m, greater<int>());     }     cout << mx <<     << mn;   }   