#include <bits/stdc++.h>
using namespace std;
vector<long long> vin(long long n) {
  vector<long long> a(n);
  for (long long i = 0; i < n; i += 1) cin >> a[i];
  return a;
}
long long intin() {
  long long n;
  cin >> n;
  return n;
}
char charin() {
  char a;
  cin >> a;
  return a;
}
string strin() {
  string s;
  cin >> s;
  return s;
}
long long factorial(long long n) {
  return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
bool p2(const pair<long long, long long> &a,
        const pair<long long, long long> &b) {
  return (a.second > b.second);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  long long t = n * (n + 1) / 2;
  k %= t;
  long long i = 1;
  while (true) {
    if (k - i < 0) break;
    if (k - i >= 0) k -= i;
    i += 1;
  }
  cout << k;
  return 0;
}
