#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  long long int n, m;
  cin >> n >> m;
  long long int cur = 1;
  while (m) {
    if (m < cur) {
      return cout << m << endl, 0;
    } else
      m -= cur;
    if (cur == n)
      cur = 1;
    else
      cur++;
  }
  cout << m << endl;
  return 0;
}
