#include <bits/stdc++.h>
using namespace std;
class Timer {
 private:
  double s_time;

 public:
  Timer() : s_time(1.0 * clock() / CLOCKS_PER_SEC) {}
  ~Timer() {
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC - s_time << '\n';
  }
};
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, c;
  cin >> n >> c;
  c = c % (n * (n + 1) / 2);
  if (c)
    for (int i = 1; i < n; ++i) {
      if (i % n <= c) {
        c -= i % n;
      } else {
        break;
      }
    }
  cout << c;
  return 0;
}
