#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  cin >> n >> a;
  a %= (n * (n + 1) / 2);
  for (int i = 1; i <= n; ++i) {
    if (a < i) {
      break;
    }
    a -= i;
  }
  cout << a << endl;
  return 0;
}
