#include #include using namespace std; int t, n; int c[22], v[22], dp[10001][1<<15]; int rec(int t, int used){ if(dp[t][used]) return dp[t][used]; int ret = 0; for(int i = 0; i < n; i++){ if(t - c[i] >= 0){ if(used >> i && 1){ int mod = v[i] % 2; v[i] /= 2; ret = max(ret, rec(t - c[i], used) + v[i]); v[i] = v[i] * 2 + mod; } else ret = max(ret, rec(t - c[i], used | (1 << i)) + v[i]); } } return dp[t][used] = ret; } int main(){ cin >> t >> n; for(int i = 0; i < n; i++) cin >> c[i]; for(int i = 0; i < n; i++) cin >> v[i]; cout << rec(t, 0) << endl; }