//sort bug下标 遍历dp.
//没修负的bug肯定连续
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int n=1e6+11;
int a,b,c[n],dp[n];
signed main()
{ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);cin>>a>>b;for(int i=1;i<=b;i++){cin>>c[i];}sort(c+1,c+1+b);int l=0;for(int i=1;i<=b;i++){dp[i]=dp[i-1]+c[i]+1;for(int j=2;j<=i;j++){if(j*j*j*j<dp[i]){dp[i]=min(dp[i-j]+j*j*j*j+c[i],dp[i]);}elsebreak;}}cout<<dp[b]<<endl;
}