#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,m,a[1000005],maxi=-1,cnt=0,maxn,k;
cin>>n>>m;
for(int i=1; i<=m; i++)cin>>a[i];
for(int i=1; i<=m; i++)maxi=max(maxi,a[i]);
for(int i=1; i<=maxi; i++){
for(int j=1; j<=m; j++){
if(a[i]>=i&&n>0){
cnt++;
n--;
}
}
if(cnt*i>maxn){
k=i;
maxn=cnt*i;
}
cnt=0;
}
cout<<k<<" "<<maxn;
return 0;
}