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