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