#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <functional>
#include <iomanip>
#include <sstream>
#include <numeric>
#define endl "\n"
#define int long long
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//pragma GCC optimize("unroll-loops")
using namespace std;
int INF=1e18;
int MOD=1e9+7;
int MOD2=1e9;
int ABCMOD=998244353;
//mac olunca template kullanmak zorundayim :/
int n,L;
vector<int> x,t;
vector<vector<int>> dp;
inline int f(int pos, int got, int time){
//poor attempt at bitmask dp implementation
if((time<=t[pos]) && !(got & (1<<pos))){
got = got | (1<<pos);
}
if(dp[pos][got]!=-1 && dp[pos][got]<=time) return 0;
dp[pos][got]=time;
int right=(pos+1)%n;
int left=(pos-1+n)%n;
int d1,d2;
if(right>=pos) d1=x[right]-x[pos];
else d1=L-x[pos]+x[right];
if(left<=pos) d2=x[pos]-x[left];
else d2=L-x[left]+x[pos];
int val=0;
for(int i=0;i<=15;i++){
if(got & (1<<i)) val++;
}
val=max(val,f(right,got,time+d1));
val=max(val,f(left,got,time+d2));
return dp[pos][got]=val;
}
inline void solve(){
cin>>n>>L;
dp.assign(n,vector<int> (1<<n,-1));
x.resize(n);
t.resize(n);
for(int i=0;i<n;i++) cin>>x[i];
for(int i=0;i<n;i++) cin>>t[i];
int ans=0;
ans=max(ans,f(0,0,x[0]));
ans=max(ans,f(n-1,0,L-x[n-1]));
cout<<ans;
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//freopen("hps.in", "r", stdin); freopen("hps.out", "w", stdout);
int T=1; //cin>>T;
while (T--){
solve();
}
}