#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> nums;
for (int i = 0; i < m; ++i)
{
int num;
cin >> num;
nums.push_back(num);
}
sort(nums.begin(), nums.end());
int cnt = 0;
int answer = 0;
int idx = 0;
for (int i = 0; i < m; ++i)
{
if (m - i <= n)
{
if (nums[i] * (m - i) > answer)
{
answer = nums[i] * (m - i);
idx = nums[i];
}
}
else
{
if (nums[i] * n > answer)
{
answer = nums[i] * n;
idx = nums[i];
}
}
}
cout << idx << ' ' << answer;
}