#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k = 1;
  scanf("%d%d", &n, &m);
  while (1) {
    if (m < k) break;
    m -= k;
    k = k % n + 1;
  }
  printf("%d\n", m);
  return 0;
}
