#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair PII; typedef vector VI; typedef vector VVI; #define MP make_pair #define PB push_back #define inf 1000000007 #define rep(i,n) for(int i=0;i<(int)(n);++i) vector > > g; int main(){ int n; ll L; cin >> n >> L; set st,st2; rep(i,n){ ll a; cin >> a; st.insert(a); } rep(i,n){ ll a; cin >> a; st2.insert(a); } ll ans = 0; ll now = 0; bool flag = 0; while(st2.size()>0){ if(!flag){ auto p = st.lower_bound(now); ll next,next2; if(p==st.end()){ next = *st.begin(); }else{ next = *p; } auto q = st2.lower_bound(next); if(q==st2.end()){ next2 = L; }else{ next2 = *q; } auto pp = st.lower_bound(next2); pp--; ll goal = *pp; if(now