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