#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3fLL; const int MAX=2e5+10; const int mod=998244353; int main() { ll x,n,sq,cnt,i; scanf("%lld%lld",&x,&n); sq=sqrt(2*x); while((1+sq)*sq/2>=x) sq--; while((1+sq)*sq/2<=x) sq++; sq=min(sq-1,n); x-=(1+sq)*sq/2; x+=(n-sq)/2; for(i=sq+(n-sq)/2*2+1;i<=n;i++) { if(x<=0) x+=i; else x-=i; } printf("%lld\n",x); return 0; }