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