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