#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main(){
vector<int> offer;
int n,m;
cin >> n >> m;
for (int i = 0;i < m;i++){
int price = 0;
cin >> price;
offer.push_back(price);
}
sort(offer.begin(),offer.end());
vector<int> profit;
for(int i = 0;i < min(m,n);i++){
int gain = 0;
gain = (min(m,n) - i)*offer[i];
profit.push_back(gain);
}
int j = 0;
while (profit[j]<profit[j+1]){
j++;
}
cout << offer[j] << " " << profit[j] << endl;
return 0;
}