#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, sum, rem;
  cin >> n >> m;
  i = 1;
  sum = 0;
  while (sum <= m && i <= n) {
    sum = sum + i;
    rem = m - sum;
    if (i == n) {
      i = 1;
    } else
      i++;
    if (rem < i || rem < 0) break;
  }
  if (rem < i)
    cout << rem;
  else
    cout << "0";
  return 0;
}
