#include <bits/stdc++.h>
using namespace std;
#define N 101
#define MM 200001
int dp[MM]={0};
int main()
{
int n, M, S;
scanf("%d %d %d", &M, &S, &n);
int w[n+1];
int sum = 0;
for (int i = 1; i <= n; i++)
{
scanf("%d", w+i);
sum += w[i];
}
int limit = M - S;
for(int i=1; i<=n; i++)
{
for(int j=limit; j>=w[i]; j--) //逆著來
{
dp[j]=max(dp[j-w[i]]+w[i],dp[j]);
}
}
printf("%d",sum-dp[limit]);
}