#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int A = 1;
  int WALRUZ;
  int CHIPS;
  int LEFTOVER = 0;
  cin >> WALRUZ >> CHIPS;
  LEFTOVER = CHIPS % ((WALRUZ + 1) * WALRUZ / 2);
  while (LEFTOVER - A >= 0) {
    LEFTOVER -= A;
    A++;
  }
  cout << LEFTOVER << endl;
}
