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