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