#include using namespace std; int main(void){ int n,m; cin >> n >> m; vector a(n+2); for(int i=1;i<=n;++i){ cin >> a[i]; } vector b(n+2); for(int i=1;i<=n;++i){ cin >> b[i]; b[i]-=a[i]; b[i]+=m; b[i]%=m; } int cnt=0; vector diff(n+1); for(int i=0;i<=n;++i){ diff[i]=b[i+1]-b[i]; if(diff[i]<0){ ++cnt; } diff[i]+=m; diff[i]%=m; } sort(diff.begin(),diff.end(),greater()); long long ans=0; for(int i=0;i