#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, sum = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) sum += i;
  while (m >= sum) m -= sum;
  if (m == 0) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i < n; i++) {
    m -= i;
    if (m < i + 1) {
      cout << m;
      return 0;
    }
  }
  return 0;
}
