#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  cin >> n >> m;
  int S = n * (n + 1) / 2;
  int max = (-1.0 + sqrt(1 + 8 * (m % S))) / 2.0;
  cout << m % S - max * (max + 1) / 2;
  return 0;
}
