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