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