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