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