#include <bits/stdc++.h>
using namespace std;
void solve(int test_number);
void pre() {
  cout.setf(ios::fixed);
  cout.precision(20);
  cerr.setf(ios::fixed);
  cerr.precision(3);
}
void post() {
  printf("\n");
  fprintf(stderr, "Execution time: %Lf", (long double)clock());
}
const int MAXN = 100100;
inline void solve(int test_number) {
  int n, m;
  scanf("%d %d", &n, &m);
  int g = m / ((n * (n + 1)) / 2);
  m -= g * ((n * (n + 1)) / 2);
  int cur = 1;
  while (m >= cur) {
    m -= cur;
    cur++;
  }
  printf("%d", m);
  return;
}
int main() {
  pre();
  int n = 1;
  for (int i = 0; i < n; i++) {
    solve(i + 1);
  }
  post();
  return 0;
}
