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