#include <bits/stdc++.h>
using namespace std;
int n, chips;
int main() {
  cin >> n >> chips;
  int i = 1;
  while (chips >= i) {
    chips -= i;
    i++;
    if (i > n) {
      i = 1;
    }
  }
  cout << chips << endl;
}
