
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
//Wrong Answer
using namespace std;
int main()
{
int NUM;
int da;
cin>>NUM>>da;
int a[NUM];
memset(a,0,sizeof(a));
int he=0;
for(int i=0;i<NUM;i++)
{
cin>>a[i];
he=a[i]+he;
}
int dp[NUM+1][he+1];
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=0;i<NUM;i++)
{
for(int j=0;j<he+1;j++)
{
if(dp[i][j]==1)
{
dp[i+1][j+a[i]]=1;
dp[i+1][j]=1;
}
}
}
/*
for(int i=0;i<NUM+1;i++)
{
for(int j=0;j<he+1;j++)
{
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
for(int j=da;j<he+1;j++)
{
if(dp[NUM][j]==1)
{
cout<<j-da;
break;
}
}
return 0;
}