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